Crashing Robots
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8124   Accepted: 3528

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 warehouseFinally 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

  1. 4
  2. 5 4
  3. 2 2
  4. 1 1 E
  5. 5 4 W
  6. 1 F 7
  7. 2 F 7
  8. 5 4
  9. 2 4
  10. 1 1 E
  11. 5 4 W
  12. 1 F 3
  13. 2 F 1
  14. 1 L 1
  15. 1 F 3
  16. 5 4
  17. 2 2
  18. 1 1 E
  19. 5 4 W
  20. 1 L 96
  21. 1 F 2
  22. 5 4
  23. 2 3
  24. 1 1 E
  25. 5 4 W
  26. 1 F 4
  27. 1 L 1
  28. 1 F 20

Sample Output

  1. Robot 1 crashes into the wall
  2. Robot 1 crashes into robot 2
  3. OK
  4. Robot 1 crashes into robot 2

Source

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<math.h>
  4. #include<string.h>
  5. using namespace std;
  6. struct robot
  7. {
  8. int x , y ;
  9. int dir ;
  10. }a[];
  11.  
  12. struct instruction
  13. {
  14. int num ;
  15. char act ;
  16. int rep ;
  17. }ins[];
  18.  
  19. int EW , NS ;
  20. int n , m ;
  21. bool flag ;
  22. int map[][];
  23.  
  24. void crash (int No)
  25. {
  26. int k = ins[No].rep ;
  27. int t = ins[No].num ;
  28. map[a[t].x][a[t].y] = ;
  29. switch (a[t].dir)
  30. {
  31. case :
  32. for (int i = ; i < k && a[t].x && a[t].y ; i++)
  33. if (map[a[t].x][++a[t].y]) {
  34. flag = ;
  35. printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
  36. break ;
  37. }
  38. break ;
  39. case :
  40. for (int i = ; i < k && a[t].x && a[t].y ; i++)
  41. if (map[++a[t].x][a[t].y]) {
  42. flag = ;
  43. printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
  44. break ;
  45. }
  46. break ;
  47. case :
  48. for (int i = ; i < k && a[t].x && a[t].y ; i++)
  49. if (map[a[t].x][--a[t].y]) {
  50. flag = ;
  51. printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
  52. break ;
  53. }
  54. break ;
  55. case :
  56. for (int i = ; i < k && a[t].x && a[t].y; i++)
  57. if (map[--a[t].x][a[t].y]) {
  58. flag = ;
  59. printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
  60. break ;
  61. }
  62. break ;
  63. }
  64. map[a[t].x][a[t].y] = t ;
  65. if (a[t].x == || a[t].x >= EW + || a[t].y == || a[t].y >= NS + ) {
  66. printf ("Robot %d crashes into the wall\n" , t) ;
  67. flag = ;
  68. }
  69. }
  70. void solve (int No)
  71. {
  72. int k = ins[No].num ;
  73. switch (ins[No].act)
  74. {
  75. case 'L' : a[k].dir -= ins[No].rep ; a[k].dir %= ; a[k].dir += ; a[k].dir %= ; break ;
  76. case 'R' : a[k].dir += ins[No].rep ; a[k].dir %= ; a[k].dir += ; a[k].dir %= ; break ;
  77. case 'F' : crash (No) ;
  78. }
  79. }
  80. int main ()
  81. {
  82. // freopen ("a.txt" , "r" , stdin) ;
  83. int T ;
  84. scanf ("%d" , &T) ;
  85. char temp ;
  86. while (T--) {
  87. memset (map , , sizeof(map) ) ;
  88. scanf ("%d%d" , &EW , &NS) ;
  89. scanf ("%d%d" , &n , &m) ;
  90. for (int i = ; i <= n ; i++) {
  91. cin >> a[i].x >> a[i].y >> temp ;
  92. // cout << temp <<endl ;
  93. map[a[i].x][a[i].y] = i ;
  94. switch (temp)
  95. {
  96. case 'E' : a[i].dir = ; break ;
  97. case 'S' : a[i].dir = ; break ;
  98. case 'W' : a[i].dir = ; break ;
  99. case 'N' : a[i].dir = ; break ;
  100. }
  101. // printf ("a[%d].dir=%d\n" , i , a[i].dir) ;
  102. }
  103. for (int i = ; i < m ; i++)
  104. cin >> ins[i].num >> ins[i].act >> ins[i].rep ;
  105.  
  106. flag = ;
  107. // printf ("a[1].dir=%d\n" , a[1].dir) ;
  108. for (int i = ; i < m ; i++) {
  109. /* for (int i = 1 ; i <= EW ; i++) {
  110. for (int j = 1 ; j <= NS ; j++) {
  111. printf ("%d " , map[i][j]) ;
  112. }
  113. puts("");
  114. }
  115. puts ("") ;*/
  116. solve (i) ;
  117. /* for (int i = 1 ; i <= EW ; i++) {
  118. for (int j = 1 ; j <= NS ; j++) {
  119. printf ("%d " , map[i][j]) ;
  120. }
  121. puts("");
  122. }
  123. printf ("\n\n\n") ; */
  124. if (flag)
  125. break ;
  126. }
  127.  
  128. if (!flag)
  129. puts ("OK") ;
  130. }
  131. return ;
  132. }

规规矩矩得模拟 robot 一步步走就行了

Crashing Robots(imitate)的更多相关文章

  1. POJ2632 Crashing Robots(模拟)

    题目链接. 分析: 虽说是简单的模拟,却调试了很长时间. 调试这么长时间总结来的经验: 1.坐标系要和题目建的一样,要不就会有各种麻烦. 2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a ...

  2. poj 2632 Crashing Robots(模拟)

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

  3. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(数学)

    题意: n 道题,2 个答题者,已知二者的做题情况,你是受贿裁判,可以给每题指定分值(≥1),求甲乙分数(甲>乙)相差最小时最大分值的最小值. 思路: 统计只有甲或乙做出的题目数. 加一取下整判 ...

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

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

  5. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  6. [AGC004E] Salvage Robots (DP)

    Description 蛤蟆国的领土我们可以抽象为H*W的笼子,在这片蛤土上,有若干个机器人和一个出口,其余都是空地,每次蛤蟆会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被蛤蟆活摘出 ...

  7. 【ZOJ1003】Crashing Balloon(DFS)

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

  8. UVALive 7464 Robots (贪心)

    Robots 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/K Description http://7xjob4.com1.z ...

  9. UVALive 7464 Robots(模拟)

    7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...

随机推荐

  1. Scala之Map,Tuple

    /** * 1,默认情况下Map构造的是不可变的集合,里面的内容不可修改,一旦修改就变成新的Map,原有的Map内容保持不变: * 2,Map的实例是调用工厂方法模式apply来构造Map实例,而需要 ...

  2. 云计算之路-阿里云上:2014年6月12日12点IIS请求到达量突降

    今天中午12:00左右,在Windows性能监视器中突然发现SLB中的两台云服务器的IIS请求到达量(ArriveRate)突然下降,见下图: IIS日志中的情况如下: 综合以上情况,我们推测在12: ...

  3. json和cookie兼容以前的

    'json': function(data) { try { if (typeof data === "string") { if (typeof JSON != 'undefin ...

  4. [USACO2005][POJ2228]Naptime(对特殊环状DP的处理)

    题目:http://poj.org/problem?id=2228 题意:将一天分为N小时,每小时都有一个价值w,有一头牛要睡觉,而它的睡觉是连续的,且第一小时不能算价值,即如果你睡了[a,b],则你 ...

  5. [USACO 1.5.4]checker(水题重做——位运算(lowbit的应用))

    描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 0 1 2 3 4 5 6 ------- ...

  6. 《TCP/IP详解卷1:协议》第6章 ICMP:Internet控制报文协议-读书笔记

    章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...

  7. opencv笔记4:模板运算和常见滤波操作

    time:2015年10月04日 星期日 00时00分27秒 # opencv笔记4:模板运算和常见滤波操作 这一篇主要是学习模板运算,了解各种模板运算的运算过程和分类,理论方面主要参考<图像工 ...

  8. NOIP2013 货车运输 (最大生成树+树上倍增LCA)

    死磕一道题,中间发现倍增还是掌握的不熟 ,而且深刻理解:SB错误毁一生,憋了近2个小时才调对,不过还好一遍AC省了更多的事,不然我一定会疯掉的... 3287 货车运输 2013年NOIP全国联赛提高 ...

  9. 【poj2773】 Happy 2006

    http://poj.org/problem?id=2773 (题目链接) 题意 给出两个数m,k,要求求出从1开始与m互质的第k个数. Solution 数据范围很大,直接模拟显然是不行的,我们需要 ...

  10. 洛谷P2024 食物链

    挺神奇 题目描述 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A 吃 B,B 吃 C,C 吃 A. 现有 N 个动物,以 1 - N 编号.每个动物都是 A,B,C 中的一种 ...