poj 2632 Crashing Robots (模拟题)
来源:互联网 发布:苹果mac os系统 编辑:程序博客网 时间:2024/04/30 09:25
Crashing Robots
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 10286 Accepted: 4362
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.
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
The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.
Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
- L: turn left 90 degrees,
- R: turn right 90 degrees, or
- F: move forward one meter,
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
Output
Output one line for each test case:
Only the first crash is to be reported.
- 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
题意:A个机器人在一个n*m的方格里,给出B种操作,其中包括左转t次(t*90),右转t次(t*90),前进t米,模拟发生的输出第一次发生的情况。
有三种情况:1、机器人走到了墙里 2、机器人和另一个机器人相遇 3、没有发生任何情况
分析:完全是个模拟题,根据给出的指令,模拟进行操作。
代码如下:
#include <stdio.h>#include <string.h>#include <map>using namespace std;struct node{int x,y;char dir;}a[105];int peace;int n,m;int Map[105][105];int index1,index2;map <int,int>left;map <int,int>right;void judge(int p,int q,char r){int i,j;if(r=='L'){char ch = a[p].dir;for(i=0;i<q;i++){ch = left[ch];}a[p].dir = ch;}else if(r=='R'){char ch = a[p].dir;for(i=0;i<q;i++){ch = right[ch];}a[p].dir = ch;}else{if(a[p].dir=='N'){Map[a[p].x][a[p].y]=0;for(i=1;i<=q && a[p].x+i<=n;i++){if(Map[a[p].x+i][a[p].y]!=0){peace=2;index1=p;index2=Map[a[p].x+i][a[p].y];break;}}if(peace==0 && a[p].x+q>n){index1=p;peace=1;}else{a[p].x+=q;Map[a[p].x][a[p].y]=p;}}else if(a[p].dir=='S'){Map[a[p].x][a[p].y]=0;for(i=1;i<=q && a[p].x-i>0;i++){if(Map[a[p].x-i][a[p].y]!=0){peace=2;index1=p;index2=Map[a[p].x-i][a[p].y];break;}}if(peace==0 && a[p].x-q<=0){index1=p;peace=1;}else{a[p].x-=q;Map[a[p].x][a[p].y]=p;}}else if(a[p].dir=='E'){Map[a[p].x][a[p].y]=0;for(i=1;i<=q && a[p].y+i<=m;i++){if(Map[a[p].x][a[p].y+i]!=0){peace=2;index1=p;index2=Map[a[p].x][a[p].y+i];break;}}if(peace==0 && a[p].y+q>m){index1=p;peace=1;}else{a[p].y+=q;Map[a[p].x][a[p].y]=p;}}else{Map[a[p].x][a[p].y]=0;for(i=1;i<=q && a[p].y-i>0;i++){if(Map[a[p].x][a[p].y-i]!=0){peace=2;index1=p;index2=Map[a[p].x][a[p].y-i];break;}}if(peace==0 && a[p].y-q<=0){index1=p;peace=1;}else{a[p].y-=q;Map[a[p].x][a[p].y]=p;}}}}int main(){int T,i,j,k,w;left['W']='S';left['N']='W';left['E']='N';left['S']='E';right['W']='N';right['N']='E';right['E']='S';right['S']='W';scanf("%d",&T);while(T--){scanf("%d %d",&m,&n);scanf("%d %d",&k,&w);memset(Map,0,sizeof(Map));for(i=1;i<=k;i++){scanf("%d %d %c",&a[i].y,&a[i].x,&a[i].dir);Map[a[i].x][a[i].y]=i;}peace=0;int p,q;char r;for(i=0;i<w;i++){scanf("%d %c %d",&p,&r,&q);if(peace==0)judge(p,q,r);}if(peace==1)printf("Robot %d crashes into the wall\n",index1);else if(peace==2)printf("Robot %d crashes into robot %d\n",index1,index2);elseprintf("OK\n");}return 0;}
0 0
- POJ 2632 Crashing Robots(模拟题)
- poj 2632 Crashing Robots (模拟题)
- POJ-2632--Crashing Robots模拟题
- POJ-2632-Crashing Robots-模拟题
- Crashing Robots(POJ 2632)(模拟)
- POJ 2632 Crashing Robots(模拟)
- poj 2632 Crashing Robots(模拟)
- POJ 2632 Crashing Robots(模拟)
- POJ 2632 Crashing Robots(简单模拟)
- poj 2632 Crashing Robots(模拟)
- POJ 2632 Crashing Robots(模拟法)
- POJ 2632 Crashing Robots (模拟)
- POJ 2632 Crashing Robots (坑爹的模拟题)
- POJ 2632 Crashing Robots 模拟
- POJ 2632 Crashing Robots 模拟
- poj 2632 Crashing Robots, 模拟
- POJ 2632-Crashing Robots(模拟)
- POJ 2632 Crashing Robots 模拟
- Technocup 2017 - Elimination Round 1 C. Guess the Array (交互题)
- labview myRIO驱动mpu6050
- 音频封装格式——AAC
- Android Studio 各类使用技巧集合(【非原创留用】)
- [noip2008] 传纸条
- poj 2632 Crashing Robots (模拟题)
- svn命令下载资源到liunx目录上
- [Usaco08Oct] Watering Hole
- 生命的力量
- 【NOIP 模拟题】[T2] 王者荣耀(二分答案+dp)
- Mysql 5.7.9以上版本 设置账户密码及授权
- Linux-CentOS6.7——安装Samba服务器
- HBase0.94和Hadoop2 结合
- LeetCode----sum-root-to-leaf-numbers