题目链接:

https://vjudge.net/problem/POJ-2632

题目大意:

在一个a×b的仓库里有n个机器人,编号为1到n。现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令,每条指令由三部分组成:整数num代表该条指令调用的机器人的编号;字符act表示操作:其中L表示原地向左转90°,R表示原地向右转90°,F表示向前走一步;整数rep表示执行该条指令的次数。已知,当两个机器人坐标相同时他们会相撞,某一个机器人走出仓库也会撞到墙,问你能否安全执行这m条指令,如果能则输出“OK”;否则输出中断原因(哪两个机器人相撞,或是哪个机器人撞到墙了)。

思路:

注意细节,直接模拟

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<queue>
  7. #include<stack>
  8. #include<map>
  9. using namespace std;
  10. typedef long long ll;
  11. const int maxn = 1e2 + ;
  12. const int INF = << ;
  13. int dir[][] = {,,,,-,,,-};
  14. int T, n, m;
  15. struct node
  16. {
  17. int x, y, dir;
  18. };
  19. node a[maxn];
  20. map<char, int>M;
  21. int Map[][];
  22. int main()
  23. {
  24. cin >> T;
  25. int c1, c2;
  26. M['E'] = ;
  27. M['N'] = ;
  28. M['W'] = ;
  29. M['S'] = ;
  30. while(T--)
  31. {
  32. cin >> n >> m;
  33. cin >> c1 >> c2;
  34. char c;
  35. memset(Map, , sizeof(Map));
  36. memset(a, , sizeof(a));
  37. for(int i = ; i <= c1; i++)
  38. {
  39. cin >> a[i].x >> a[i].y >> c;
  40. a[i].dir = M[c];
  41. Map[a[i].x][a[i].y] = i;
  42. }
  43. int flag = , ansid1, ansid2;
  44. for(int i = ; i <= c2; i++)
  45. {
  46. int id, tot;
  47. cin >> id >> c >> tot;
  48. if(flag)continue;
  49. if(c == 'L')
  50. {
  51. a[id].dir += tot;
  52. a[id].dir %= ;
  53. }
  54. else if(c == 'R')
  55. {
  56. a[id].dir -= tot;
  57. a[id].dir = ((a[id].dir % ) + ) % ;
  58. }
  59. else if(c == 'F')
  60. {
  61. Map[a[id].x][a[id].y] = ;
  62. for(int i = ; i <= tot; i++)
  63. {
  64. //cout<<a[id].x<<" "<<a[id].y<<" "<<a[id].dir<<endl;
  65. a[id].x += dir[a[id].dir][];
  66. a[id].y += dir[a[id].dir][];
  67.  
  68. if(a[id].x <= || a[id].x > n || a[id].y <= || a[id].y > m)
  69. {
  70. flag = ;
  71. ansid1 = id;
  72. break;
  73. }
  74. else if(Map[a[id].x][a[id].y])
  75. {
  76. flag = ;
  77. ansid1 = id;
  78. ansid2 = Map[a[id].x][a[id].y];
  79. }
  80. if(flag)break;
  81. }
  82. Map[a[id].x][a[id].y] = id;
  83. }
  84. }
  85. if(!flag)cout<<"OK"<<endl;
  86. else if(flag == )
  87. cout<<"Robot "<<ansid1<<" crashes into the wall"<<endl;
  88. else cout<<"Robot "<<ansid1<<" crashes into robot "<<ansid2<<endl;
  89. }
  90. return ;
  91. }

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

  1. poj 2632 Crashing Robots 模拟

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

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

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

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

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

  4. 模拟 POJ 2632 Crashing Robots

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

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

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

  6. poj 2632 Crashing Robots(模拟)

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

  7. poj 2632 Crashing Robots

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

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

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

  9. poj 2632 Crashing Robots_模拟

    做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...

  10. Poj OpenJudge 百练 2632 Crashing Robots

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

随机推荐

  1. OpenCV与Qt的环境搭建及Demo

    前言: 前段时间写了很多OpenCV的程序,虽然重点在算法上,但图像窗口只能靠cvNamedWindow,效果很不理想.遂希望用Qt配合OpenCV使用,为我的程序建立图形化界面.然而,依我对Open ...

  2. 笔记:Maven 项目基本配置

    Maven 的基本设置包含项目基本信息和项目信息,基本信息主要用于设置当前包的归属项目.当前项目等,配置文件结构如下: <project xmlns="http://maven.apa ...

  3. Python中的PYTHONPATH环境变量

    PYTHONPATH是Python中一个重要的环境变量,用于在导入模块的时候搜索路径.可以通过如下方式访问: >>> import sys >>> sys.path ...

  4. spring框架学习笔记5:SpringAOP示例

    1.导包: 导入spring中的这两个包 再导入其他包(网上下载): 2.准备目标对象: package service; public class UserServiceImpl implement ...

  5. 105&250-高级软件工程2017第3次作业

    小组成员 2017282110250 王婷婷 2017202110105 张芷祎 github地址 https://github.com/setezzy/Calculator_GUI PSP PSP2 ...

  6. Beta版本敏捷冲刺每日报告——Day2

    1.情况简述 Beta阶段第二次Scrum Meeting 敏捷开发起止时间 2017.11.3 08:00 -- 2017.11.3 22:00 讨论时间地点 2017.11.3晚9:00,软工所实 ...

  7. Beta阶段敏捷冲刺报告-DAY3

    Beta阶段敏捷冲刺报告-DAY3 Scrum Meeting 敏捷开发日期 2017.11.4 会议时间 12:30 会议地点 软工所 参会人员 全体成员 会议内容 当天任务确认,进度调整, 讨论时 ...

  8. Week04-面向对象设计与继承

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 is a关系 覆盖 Object 超级父类 继承 抽象类 多态 重载 static super private public p ...

  9. java实现找一个数范围内所有的一

    一.题目内容 给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数.要求:写一个函数 f(N) ,返回1 到 N 之间出现的 “1”的个数.例如 f(12)  = 5. ...

  10. Python多线程案例

    from time import ctime,sleep import threading def music(): for i in range(2): print ("I was lis ...