poj 2632 Crashing Robots
http://poj.org/problem?id=2632
题意:机器人是否撞墙撞车
分析:这里不同的就是机器人每次的行为都必须判断一次,出现问题后马上退出判断
#include<stdio.h> const int MAXN=110; struct Node { int row,col; int drec; int flag;//-1撞墙,0存活,-2 } node[MAXN]; int main() { int judge; int i,j,T,A,B,m,n,k; int rep,drec,rob; char act; scanf("%d",&T); while(T--) { judge=0; scanf("%d%d",&A,&B);//A列 B行 scanf("%d%d",&n,&m); for(i=1; i<=n; i++) { scanf("%d%d",&node[i].col,&node[i].row); getchar(); scanf("%c",&node[i].drec); node[i].flag=0; if(node[i].drec=='N') node[i].drec=0; if(node[i].drec=='W') node[i].drec=1; if(node[i].drec=='S') node[i].drec=2; if(node[i].drec=='E') node[i].drec=3; } for(i=0; i<m; i++) { scanf("%d",&rob); getchar(); scanf("%c%d",&act,&rep); if(judge==1) continue; if(act=='F') { for(j=1; j<=rep; j++) { if(judge==1) break; if(node[rob].drec==0) node[rob].row++; if(node[rob].drec==1) node[rob].col--; if(node[rob].drec==2) node[rob].row--; if(node[rob].drec==3) node[rob].col++; if(node[rob].row>B || node[rob].row==0 || node[rob].col>A || node[rob].col==0) { judge=1; printf("Robot %d crashes into the wall\n",rob); break; } for(k=1; k<=n; k++) { if(k==rob) continue; if(node[k].row==node[rob].row && node[k].col==node[rob].col) { judge=1; printf("Robot %d crashes into robot %d\n",rob,k); break; } } } } else if(act=='L') { rep%=4; node[rob].drec=(node[rob].drec+rep)%4; } else { rep%=4; node[rob].drec=(node[rob].drec-rep+4)%4; } } if(judge==0) printf("OK\n"); } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步