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 <map> #include <cstring> using namespace std; char d[]={'N','E','S','W'}; bool postion[205][205]; bool crash[505]; bool is_OK; struct coordinate { int x,y; char direction; }; map<int,coordinate>robot; int main() { int K; cin>>K; while(K--) { memset(postion,false,sizeof(postion)); memset(crash,false,sizeof(crash)); bool c=false; robot.clear(); int A,B,N,M; cin>>A>>B>>N>>M; coordinate p; for(int i=1;i<=N;++i) { cin>>p.x>>p.y>>p.direction; robot[i]=p; postion[p.x][p.y]=true; } is_OK=true; while(M--) { int number; char direction; int repeat; cin>>number>>direction>>repeat; if(crash[number]==true)continue; if(c)continue; if(direction=='F') { postion[robot[number].x][robot[number].y]=false; bool collide=false; bool safe=true; int collide_number=-1; switch (robot[number].direction) { case 'N': for(int i=1;i<=repeat;++i) { robot[number].y++; if(robot[number].y>B)safe=false; if(safe && postion[robot[number].x][robot[number].y]) { postion[robot[number].x][robot[number].y]=false; collide=true; is_OK=false; for(map<int,coordinate>::iterator it=robot.begin();it!=robot.end();++it) if(it->first!=number && it->second.y==robot[number].y && it->second.x==robot[number].x)collide_number=it->first; break; } } if(safe)postion[robot[number].x][robot[number].y]=true; break; case 'E': for(int i=1;i<=repeat;++i) { robot[number].x++; if(robot[number].x>A)safe=false; if(safe && postion[robot[number].x][robot[number].y]) { postion[robot[number].x][robot[number].y]=false; collide=true; is_OK=false; for(map<int,coordinate>::iterator it=robot.begin();it!=robot.end();++it) if(it->first!=number && it->second.y==robot[number].y && it->second.x==robot[number].x)collide_number=it->first; break; } } if(safe)postion[robot[number].x][robot[number].y]=true; break; case 'S': for(int i=1;i<=repeat;++i) { robot[number].y--; if(robot[number].y<1)safe=false; if(safe && postion[robot[number].x][robot[number].y]) { postion[robot[number].x][robot[number].y]=false; collide=true; is_OK=false; for(map<int,coordinate>::iterator it=robot.begin();it!=robot.end();++it) if(it->first!=number && it->second.y==robot[number].y && it->second.x==robot[number].x)collide_number=it->first; break; } } if(safe)postion[robot[number].x][robot[number].y]=true; break; case 'W': for(int i=1;i<=repeat;++i) { robot[number].x--; if(robot[number].x<1)safe=false; if(safe && postion[robot[number].x][robot[number].y]) { postion[robot[number].x][robot[number].y]=false; collide=true; is_OK=false; for(map<int,coordinate>::iterator it=robot.begin();it!=robot.end();++it) if(it->first!=number && it->second.y==robot[number].y && it->second.x==robot[number].x)collide_number=it->first; break; } } if(safe)postion[robot[number].x][robot[number].y]=true; break; } crash[number]=true; if(collide) { c=true; cout<<"Robot "<<number<<" crashes into robot "<<collide_number<<endl; is_OK=false; } else { if(safe) crash[number]=false; else { c=true; cout<<"Robot "<<number<<" crashes into the wall"<<endl; is_OK=false; } } } if(direction=='R') { repeat%=4; while(repeat--) for(int i=0;i!=4;++i) if(d[i]==robot[number].direction){robot[number].direction=d[(i+1)%4];break;} } if(direction=='L') { repeat%=4; while(repeat--) for(int i=0;i<4;++i) if(d[i]==robot[number].direction){if(i<1)i+=4;robot[number].direction=d[(i-1)%4];break;} } } if(is_OK)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