Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么你给的所有数据我都过了我还是WA?????!!!!!In Reply To:Re:给wa的同学一组数据 补充几个容易WA的地方 Posted by:MDK at 2011-11-07 21:58:44 #include <iostream> using namespace std; int ok[101][101]={0}; int num,m; int t,l,w; int pos[3][101]; char dir[101]; int sqt[101],rpt[101]; char idt[101]; bool k; bool crash(int n,char d,int r) { ok[pos[1][n]][pos[2][n]]=0; k=true; for (int i=0;i<r;i++) { switch(d) { case 'N':pos[2][n]++;break; case 'S':pos[2][n]--;break; case 'W':pos[1][n]--;break; case 'E':pos[1][n]++;break; default: break; } for (int j=1;j<=num;j++) { if(ok[pos[1][j]][pos[2][j]]==1&&pos[1][j]==pos[1][n]&&pos[2][j]==pos[2][n]&&j!=n) { cout<<"Robot "<<n<<" crashes into robot "<<j<<endl; k=false; goto end; } } if(k&&(pos[1][n]<1||pos[1][n]>l||pos[2][n]<1||pos[2][n]>w)) { cout<<"Robot "<<n<<" crashes into wall"<<endl; k=false; break; } } if(k) ok[pos[1][n]][pos[2][n]]=1; end: return k; } void turnleft(int n,char &q,int r) { int r1=r%4; switch(q) { case 'N': switch(r1) { case 0: break; case 1: q='W'; break; case 2: q='S'; break; case 3: q='E'; break; } break; case 'W': switch(r1) { case 0: break; case 1: q='S'; break; case 2: q='E'; break; case 3: q='N'; break; } break; case 'S': switch(r1) { case 0: break; case 1: q='E'; break; case 2: q='N'; break; case 3: q='W'; break; } break; case 'E': switch(r1) { case 0: break; case 1: q='N'; break; case 2: q='W'; break; case 3: q='S'; break; } break; } } void turnright(int n,char &q,int r) { int r1=r%4; switch(q) { case 'N': switch(r1) { case 0: break; case 1: q='E'; break; case 2: q='S'; break; case 3: q='W'; break; } break; case 'W': switch(r1) { case 0: break; case 1: q='N'; break; case 2: q='E'; break; case 3: q='S'; break; } break; case 'S': switch(r1) { case 0: break; case 1: q='W'; break; case 2: q='N'; break; case 3: q='E'; break; } break; case 'E': switch(r1) { case 0: break; case 1: q='S'; break; case 2: q='W'; break; case 3: q='N'; break; } break; } } int main() { cin>>t; while(t--) { k=true; cin>>l>>w; cin>>num>>m; int i,j; for (i=1;i<=w;i++) for (j=1;j<=l;j++) ok[i][j]=0; for (i=1;i<=num;i++) { cin>>pos[1][i]>>pos[2][i]>>dir[i]; ok[pos[1][i]][pos[2][i]]=1; } for (i=1;i<=m;i++) cin>>sqt[i]>>idt[i]>>rpt[i]; for (i=1;i<=m;i++) { switch(idt[i]) { case 'F': k=crash(sqt[i],dir[sqt[i]],rpt[i]); if(!k) i=m; break; case 'L': turnleft(sqt[i],dir[sqt[i]],rpt[i]); break; case 'R': turnright(sqt[i],dir[sqt[i]],rpt[i]); break; } } if(k) cout<<"OK"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator