Crashing Robots

Time Limit: 1000MS Memory Limit: 65536K

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

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

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:

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

4

5 4

2 2

1 1 E

5 4 W

1 F 7

2 F 7

5 4

2 4

1 1 E

5 4 W

1 F 3

2 F 1

1 L 1

1 F 3

5 4

2 2

1 1 E

5 4 W

1 L 96

1 F 2

5 4

2 3

1 1 E

5 4 W

1 F 4

1 L 1

1 F 20

Sample Output

Robot 1 crashes into the wall

Robot 1 crashes into robot 2

OK

Robot 1 crashes into robot 2


  • 题意就是给你一个图里面有很多机器人,每个机器人可以自身向左转或者右转(90度)或者向前走每个动作重复k次。输出机器人第一次撞到墙或者第一次撞到其他的机器人(机器人按照指令依次执行)。只输出第一次撞击,之后的不管。

  • 真的是反向建图日神仙,本来就是东西南北傻傻分不清,xy还反着输入,图的行列也是反着的。对于方向感不强的人来说简直是折磨啊。其实只要弄清楚方向,这个题很简单就可以过了。


  1. #include<stdio.h>
  2. #include<cstring>
  3. using namespace std;
  4. struct roob
  5. {
  6. int x,y;
  7. char dir[10];
  8. } r[110];
  9. bool r_pos[310][310];//标记图中机器人的位置
  10. char Dir[10]= "0NESW";//用来计算机器人的转向
  11. int n,m,x,y;
  12. void init()
  13. {
  14. memset(r_pos,0,sizeof(r_pos));
  15. scanf("%d%d",&y,&x);//xy反着输入的
  16. scanf("%d%d",&n,&m);
  17. for(int i=1; i<=n; i++)
  18. {
  19. scanf("%d%d%s",&r[i].y,&r[i].x,&r[i].dir);
  20. r_pos[r[i].x][r[i].y] = true;
  21. }
  22. }
  23. bool check(int w,int times)//机器人w向前走times步
  24. {
  25. roob now = r[w];
  26. int x1 = now.x;
  27. int y1 = now.y;
  28. r_pos[x1][y1] = false;//走了之后记得取消标记
  29. if(now.dir[0] == 'N')
  30. {
  31. for(int i=1; i<=times; i++)
  32. {
  33. int x2 = x1+i;
  34. if(r_pos[x2][y1])
  35. {
  36. for(int i=1; i<=n; i++)
  37. if(r[i].x == x2 && r[i].y == y1)
  38. {
  39. printf("Robot %d crashes into robot %d\n",w,i);
  40. return true;
  41. }
  42. }
  43. }
  44. x1 += times;
  45. }
  46. else if(now.dir[0] == 'S')
  47. {
  48. for(int i=1; i<=times; i++)
  49. {
  50. int x2 = x1-i;
  51. if(r_pos[x2][y1])
  52. {
  53. for(int i=1; i<=n; i++)
  54. if(r[i].x == x2 && r[i].y == y1)
  55. {
  56. printf("Robot %d crashes into robot %d\n",w,i);
  57. return true;
  58. }
  59. }
  60. }
  61. x1 -= times;
  62. }
  63. else if(now.dir[0] == 'E')
  64. {
  65. for(int i=1; i<=times; i++)
  66. {
  67. int y2 = y1+i;
  68. if(r_pos[x1][y2])
  69. {
  70. for(int i=1; i<=n; i++)
  71. if(r[i].x == x1 && r[i].y == y2)
  72. {
  73. printf("Robot %d crashes into robot %d\n",w,i);
  74. return true;
  75. }
  76. }
  77. }
  78. y1 += times;
  79. }
  80. else if(now.dir[0] == 'W')
  81. {
  82. for(int i=1; i<=times; i++)
  83. {
  84. int y2 = y1-i;
  85. if(y2 < 1)
  86. continue;
  87. if(r_pos[x1][y2])
  88. {
  89. for(int i=1; i<=n; i++)
  90. if(r[i].x == x1 && r[i].y == y2)
  91. {
  92. printf("Robot %d crashes into robot %d\n",w,i);
  93. return true;
  94. }
  95. }
  96. }
  97. y1 -= times;
  98. }
  99. if(x1<1 || y1<1 || x1>x || y1>y)//走到地图外面去了
  100. {
  101. printf("Robot %d crashes into the wall\n",w);
  102. return true;
  103. }
  104. r_pos[x1][y1] = true;//到达新的地点被标记
  105. r[w].x = x1;
  106. r[w].y = y1;
  107. return false;
  108. }
  109. void solve()
  110. {
  111. bool flag = false;//标记是否发生第一次撞击
  112. while(m--)
  113. {
  114. int w,times;
  115. char d[10];
  116. scanf("%d%s%d",&w,d,&times);
  117. if(flag)//发生第一次撞击之后都不用管了
  118. continue;
  119. int temp2;
  120. if(r[w].dir[0] == 'N')
  121. temp2 = 1;
  122. else if(r[w].dir[0] == 'E')
  123. temp2 = 2;
  124. else if(r[w].dir[0] == 'S')
  125. temp2 = 3;
  126. else if(r[w].dir[0] == 'W')
  127. temp2 = 4;
  128. if(d[0] == 'F')
  129. flag = check(w,times);
  130. else if(d[0] == 'L')//向左转的计算
  131. {
  132. times %= 4;
  133. temp2 -= times;
  134. if(temp2 < 1)
  135. temp2 += 4;
  136. r[w].dir[0] = Dir[temp2];
  137. }
  138. else if(d[0] == 'R')//向右转的计算
  139. {
  140. times %= 4;
  141. temp2 += times;
  142. if(temp2 > 4)
  143. temp2 %= 4;
  144. r[w].dir[0] = Dir[temp2];
  145. }
  146. }
  147. if(!flag)
  148. printf("OK\n");
  149. }
  150. int main()
  151. {
  152. int t;
  153. scanf("%d",&t);
  154. while(t--)
  155. {
  156. init();
  157. solve();
  158. }
  159. return 0;
  160. }

POJ:2632-Crashing Robots的更多相关文章

  1. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  2. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  3. POJ 2632 Crashing Robots (坑爹的模拟题)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6599   Accepted: 2854 D ...

  4. poj 2632 Crashing Robots

    点击打开链接 Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6655   Accepted: ...

  5. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

  6. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  7. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

  8. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  9. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  10. POJ 2632:Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8424   Accepted: 3648 D ...

随机推荐

  1. (转)sudo配置文件/etc/sudoers详解及实战用法

    sudo配置文件/etc/sudoers详解及实战用法 原文:http://blog.csdn.net/field_yang/article/details/51547804 一.sudo执行命令的流 ...

  2. 项目协作管理平台-teambition和tapd--深度体验

    ​ 一.分析目的 通过分析2B产品中的团队协作管理软件的对比分析,用于为公司团队协作软件的选型做产考. 二.竞品归属市场概况 2.1.目标用户群及需求 主要面向企业用户,用于解决企业不同地域以及不同职 ...

  3. 使用history.replaceState 修改url 不跳转

    history.replaceState(null,null,this.urlR);  //关键代码 history.replaceState是将指定的URL替换当前的URL 注意:用于替换掉的URL ...

  4. <Android 应用 之路> 天气预报(二)

    界面组成 载入界面 显示界面 Activity两个,一个用来显示载入界面,一个用来显示天气信息 主要代码如下: public class MyActivity extends Activity { p ...

  5. Vmware 虚拟硬盘 合并多个分割文件

    有时,当我们创建虚拟机vmware里面的应用程序,我们可能会选择创建分割的虚拟磁盘中的多个文件2 GB的文件,这是为了提高复制过程,主要用于存储虚拟机文件系统不支持创建更大的文件. 如果我们需要将它转 ...

  6. LNK2005错误——重复定义错误

    编程中经常能遇到LNK2005错误——重复定义错误,其实LNK2005错误并不是一个很难解决的错误.弄清楚它形成的原因,就可以轻松解决它了. 造成LNK2005错误主要有以下几种情况: 1.重复定义全 ...

  7. put_user

    1. put_user Name put_user --    Write a simple value into user space. Synopsis put_user ( x, ptr); A ...

  8. SqlServer中提示和报错信息的翻译

    有时候遇到SqlServer一些报错需要上网查找解决方法,一些比较生僻的问题汉语搜索往往得不到想要的,就要使用英文在外网搜索.之前都是自己尝试翻译,或者使用错误码,或者找个英文版的数据库重现问题.有时 ...

  9. UVA Planning mobile robot on Tree树上的机器人(状态压缩+bfs)

    用(x,s)表示一个状态,x表示机器人的位置,s表示其他位置有没有物体.用个fa数组和act数组记录和打印路径,转移的时候判断一下是不是机器人在动. #include<bits/stdc++.h ...

  10. [学习笔记] C++ 历年试题解析(三)--小补充

    小小的补充一下吧,因为李老师又把直招的卷子发出来了.. 题目 1.有指针变量定义及初始化int *p=new int[10];执行delete [] p;操作将结束指针变量p的生命期.(×) 解释:试 ...