POJ 2632 Crashing Robots (模拟)

网友投稿 420 2022-11-09

POJ 2632 Crashing Robots (模拟)

POJ 2632 Crashing Robots (模拟)

Description

In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving. A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.

Input

Output

Output one line for each test case: Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.) Robot i crashes into robot j, if robots i and j crash, and i is the moving robot. OK, if no crashing occurs.Only the first crash is to be reported.

Sample Input

45 42 21 1 E5 4 W1 F 72 F 75 42 41 1 E5 4 W1 F 32 F 11 L 11 F 35 42 21 1 E5 4 W1 L 961 F 25 42 31 1 E5 4 W1 F 41 L 11 F 20

Sample Output

Robot 1 crashes into the wallRobot 1 crashes into robot 2OKRobot 1 crashes into robot 2

题意

给出所有机器人的初始位置以及它的方向,然后对这些机器人进行操作,操作的方式有三种:左转、右转、前行,判断并输出在执行这些操作的时候机器人是否碰到墙(边界),或者是否与其他机器人相遇,若都没有,则输出 ​​OK​​ 。

思路

因为题目给出的数据范围很小,所以直接模拟便可,左转n次或者右转n次都相当于转动n%4次。

AC 代码

#include#include#include#include#include#includeusing namespace std;#include#includeint mv[4][2]= {{1,0},{0,-1},{-1,0},{0,1}}; //移动数组 逆时针struct point{ int x; int y; int face; void init(int x,int y,char f) { this->x=x; this->y=y; if(f=='E')face=3; else if(f=='N')face=0; else if(f=='W')face=1; else if(f=='S')face=2; }} a[105];int mapx,mapy; //地图边界int mapp[105][105]; //地图各点的状态 -1表示空 其他表示当前点的机器人编号int main(){ int T; scanf("%d",&T); while(T--) { int n,m,x,y; char c; bool flag=true; memset(mapp,-1,sizeof(mapp)); scanf("%d%d%d%d",&mapy,&mapx,&n,&m); for(int i=0; i=mapx||*ny>=mapy) //如果越过边界 { printf("Robot %d crashes into the wall\n",x); flag=false; break; } else if(mapp[*nx][*ny]>0) //如果当前点有其他机器人 { printf("Robot %d crashes into robot %d\n",x,mapp[*nx][*ny]); flag=false; break; } } mapp[*nx][*ny]=x; //标记当前点所在机器人 } else { y%=4; //转4次相当于没有转动 if(c=='L') a[x-1].face=(a[x-1].face+y)%4; //计算转完之后的方向 else if(c=='R') a[x-1].face=(a[x-1].face+4-y)%4; } } if(flag)printf("OK\n"); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:HDU 5907:Find
下一篇:POJ 3096 Surprising Strings (枚举)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~