QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720838 | #9521. Giving Directions in Harbin | KOH-# | WA | 0ms | 3656kb | C++14 | 2.4kb | 2024-11-07 14:22:58 | 2024-11-07 14:23:00 |
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--){
memset(vis,0,sizeof(vis));
ans.clear();
ans.clear();
int n;read(n);
int nowx=0,nowy=0;
int edx=0,edy=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;
for(int i=now+2;i<=cnt;++i){
if(loc[i].first!=loc[now].first) break;
tmp=i;
}
if(loc[tmp].second==loc[now].second) continue;
else 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;
for(int i=now+2;i<=cnt;++i){
if(loc[i].second!=loc[now].second) break;
tmp=i;
}
if(loc[tmp].first==loc[now].first) continue;
else 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;
}
}
if(ans.size()==0){
print(0),putchar('\n');
}
else{
print(ans.size()),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');
}
}
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
1 2 S 2 E 1
output:
2 S Z 2 L Z 1
result:
wrong answer Wrong destination (test case 1)