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 |
不行了,被恶心到了,方向什么的现在完全搞不清楚了,哪位大神帮咱看一下,要哭了#include <iostream> #include <cstring> using namespace std; struct node { int r,c; } robot[101]; int main() { int k,a,b,n,m;//a,b长宽,n robots,m命令数 int x,y; int crash,crashrobot; int direction[101]; char z; int map[101][101]; cin>>k; while(k--) { crash=0; memset(robot,0,sizeof(robot)); memset(direction,0,sizeof(direction)); cin>>b>>a; cin>>n>>m; for(int i=0; i<n; i++) { cin>>y>>x>>z; map[x][y]=i+1; robot[i+1].r=x; robot[i+1].c=y; switch(z) { case 'N' : direction[i+1]=3; break; case 'S' : direction[i+1]=1; break; case 'W' : direction[i+1]=2; break; case 'E' : direction[i+1]=0; break; } } for(int i=0; i<m; i++) { cin>>x>>z>>y; if(!crash) { switch(z) { case 'L' : y%=4; direction[x]=(direction[x]+4-y)%4; break; case 'R' : y%=4; direction[x]=(direction[x]+y)%4; break; case 'F' : if(direction[x]==0) { while(y--) { map[robot[x].r][robot[x].c]=0; robot[x].c++; if(robot[x].c==b+1) { crash=-1; crashrobot=x; break; } if(map[robot[x].r][robot[x].c]) { crash=map[robot[x].r][robot[x].c]; crashrobot=x; break; } map[robot[x].r][robot[x].c]=x; // cout<<"当前位置"<<robot[x].r<<' '<<robot[x].c<<endl; } } else if(direction[x]==1) { while(y--) { map[robot[x].r][robot[x].c]=0; robot[x].r--; if(robot[x].r==0) { crash=-1; crashrobot=x; break; } else if(map[robot[x].r][robot[x].c]) { crash=map[robot[x].r][robot[x].c]; crashrobot=x; break; } map[robot[x].r][robot[x].c]=x; // cout<<"当前位置"<<robot[x].r<<' '<<robot[x].c<<endl; } } else if(direction[x]==2) { while(y--) { map[robot[x].r][robot[x].c]=0; robot[x].c--; if(robot[x].c==0) { crash=-1; crashrobot=x; break; } else if(map[robot[x].r][robot[x].c]) { crash=map[robot[x].r][robot[x].c]; crashrobot=x; break; } map[robot[x].r][robot[x].c]=x; // cout<<"当前位置"<<robot[x].r<<' '<<robot[x].c<<endl; } } else { while(y--) { map[robot[x].r][robot[x].c]=0; robot[x].r++; if(robot[x].r==a+1) { crash=-1; crashrobot=x; break; } else if(map[robot[x].r][robot[x].c]) { crash=map[robot[x].r][robot[x].c]; crashrobot=x; break; } map[robot[x].r][robot[x].c]=x; // cout<<"当前位置"<<robot[x].r<<' '<<robot[x].c<<endl; } } } } } if(crash) { if(crash==-1) cout<<"Robot "<<crashrobot<<" crashes into the wall"<<endl; else cout<<"Robot "<<crashrobot<<" crashes into robot "<<crash<<endl; } else 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