QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720990 | #9521. Giving Directions in Harbin | KOH-# | AC ✓ | 8ms | 3688kb | C++14 | 2.1kb | 2024-11-07 14:54:49 | 2024-11-07 14:54:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
x=0;char ch=getchar();bool f=false;
while(!isdigit(ch)) f|=ch=='-',ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=f?-x:x;return;
}
template <typename T>
inline void print(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) print(x/10);
putchar(x%10^48);return;
}
#define ll long long
const int N=103;
int T;
pair<int,int> dir[6]={{0,1},{0,-1},{-1,0},{1,0}};
map<char,int> rev;
bool vis[203][203];
pair<int,int> loc[N];
vector<pair<char,int> > ans;
int main(){
read(T);
rev['N']=0,rev['S']=1,rev['W']=2,rev['E']=3;
while(T--){
ans.clear();
int n;read(n);
int nowx=0,nowy=0;
int cnt=0;
loc[++cnt]=make_pair(0,0);
for(int i=1;i<=n;++i){
char o;int x;cin>>o;read(x);
int op=rev[o];
nowx+=x*dir[op].first,nowy+=x*dir[op].second;
loc[++cnt]=make_pair(nowx,nowy);
}
// puts("????");
int now=1;
while(now<cnt){
// cout<<now<<"???";
if(loc[now+1].first==loc[now].first){
int tmp=now+1;
if(loc[tmp].second>loc[now].second) ans.push_back(make_pair('N',loc[tmp].second-loc[now].second));
else ans.push_back(make_pair('S',loc[now].second-loc[tmp].second));
now=tmp;
}
else{
int tmp=now+1;
if(loc[tmp].first>loc[now].first) ans.push_back(make_pair('E',loc[tmp].first-loc[now].first));
else ans.push_back(make_pair('W',loc[now].first-loc[tmp].first));
now=tmp;
}
}
print(ans.size()*2-1),putchar(' '),putchar(ans[0].first),putchar('\n');
char lst=ans[0].first;
for(int i=0;i<ans.size();++i){
if(ans[i].first==lst){
putchar('Z'),putchar(' '),print(ans[i].second),putchar('\n');
}
else{
char tmp=ans[i].first;
if(lst=='W'&&tmp=='N'||lst=='N'&&tmp=='E'||lst=='E'&&tmp=='S'||lst=='S'&&tmp=='W') tmp='R';
else tmp='L';
putchar(tmp),putchar('\n');
putchar('Z'),putchar(' '),print(ans[i].second),putchar('\n');
}
lst=ans[i].first;
}
}
return 0;
}
/*
2
3
S 2
E 1
N 3
3
S 2
E 1
N 3
*/
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
input:
1 2 S 2 E 1
output:
3 S Z 2 L Z 1
result:
ok ok (1 test case)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
99 4 E 6 N 1 W 2 S 8 8 W 10 N 1 E 10 S 2 E 2 N 2 W 2 S 1 9 N 5 E 4 N 7 E 6 S 9 E 8 N 4 W 6 N 7 6 N 6 E 6 N 8 W 9 S 7 E 2 8 E 6 S 9 W 5 S 4 W 6 N 4 E 5 N 9 8 N 6 W 10 N 6 W 6 S 6 E 6 S 6 E 10 10 N 7 W 3 N 5 W 5 S 8 W 10 N 6 E 9 N 8 E 8 8 W 9 N 10 E 6 S 10 E 9 S 10 W 6 N 10 4 W 5 N 1 E 5 S 1 4 W 4 S 8...
output:
7 E Z 6 L Z 1 L Z 2 L Z 8 15 W Z 10 R Z 1 R Z 10 R Z 2 L Z 2 L Z 2 L Z 2 L Z 1 17 N Z 5 R Z 4 L Z 7 R Z 6 R Z 9 L Z 8 L Z 4 L Z 6 R Z 7 11 N Z 6 R Z 6 L Z 8 L Z 9 L Z 7 L Z 2 15 E Z 6 R Z 9 R Z 5 L Z 4 R Z 6 R Z 4 R Z 5 L Z 9 15 N Z 6 L Z 10 R Z 6 L Z 6 L Z 6 L Z 6 R Z 6 L Z 10 19 N Z 7 L Z 3 R Z 5 ...
result:
ok ok (99 test cases)
Test #3:
score: 0
Accepted
time: 8ms
memory: 3688kb
input:
10000 1 W 9 1 N 3 10 W 10 N 7 W 5 S 9 W 9 S 8 E 9 S 6 E 5 S 5 2 E 8 S 10 2 N 7 W 5 5 S 4 W 3 S 7 E 4 N 7 8 N 7 E 8 N 3 E 9 S 5 W 5 S 9 W 10 9 W 9 S 6 E 6 N 8 W 5 N 6 W 3 N 8 W 7 3 S 9 W 2 N 10 5 N 6 E 4 N 6 E 10 N 1 10 S 7 W 4 N 3 E 5 S 7 W 8 N 2 E 8 N 4 W 8 8 S 9 W 1 N 4 E 6 N 1 W 8 N 6 W 6 4 W 10 ...
output:
1 W Z 9 1 N Z 3 19 W Z 10 R Z 7 L Z 5 L Z 9 R Z 9 L Z 8 L Z 9 R Z 6 L Z 5 R Z 5 3 E Z 8 R Z 10 3 N Z 7 L Z 5 9 S Z 4 R Z 3 L Z 7 L Z 4 L Z 7 15 N Z 7 R Z 8 L Z 3 R Z 9 R Z 5 R Z 5 L Z 9 R Z 10 17 W Z 9 L Z 6 L Z 6 L Z 8 L Z 5 R Z 6 L Z 3 R Z 8 L Z 7 5 S Z 9 R Z 2 R Z 10 9 N Z 6 R Z 4 L Z 6 R Z 10 L ...
result:
ok ok (10000 test cases)
Extra Test:
score: 0
Extra Test Passed