传送门
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
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
bool judge = false;
int rect[101][101];
int A, B;//边界
struct robot
{int x, y;char direct;
}rob[101];
struct intstruction
{int ID;char act;int repeat;
}ist[101];
void F(int ID, int repeat)//移动
{if (rob[ID].direct == 'E'){for (int i = 1; i <= repeat; i++){if (rob[ID].x + i > A){judge = true;cout << "Robot " << ID << " crashes into the wall" << endl;return;}if (rect[rob[ID].y][rob[ID].x + i] != 0){judge = true;cout << "Robot " << ID << " crashes into robot " << rect[rob[ID].y][rob[ID].x + i] << endl;return;}}rect[rob[ID].y][rob[ID].x] = 0;rob[ID].x += repeat;rect[rob[ID].y][rob[ID].x] = ID;}else if (rob[ID].direct == 'W'){for (int i = 1; i <= repeat; i++){if (rob[ID].x - i < 1){judge = true;cout << "Robot " << ID << " crashes into the wall" << endl;return;}if (rect[rob[ID].y][rob[ID].x - i] != 0){judge = true;cout << "Robot " << ID << " crashes into robot " << rect[rob[ID].y][rob[ID].x - i] << endl;return;}}rect[rob[ID].y][rob[ID].x] = 0;rob[ID].x -= repeat;rect[rob[ID].y][rob[ID].x] = ID;}else if (rob[ID].direct == 'N'){for (int i = 1; i <= repeat; i++){if (rob[ID].y + i > B){judge = true;cout << "Robot " << ID << " crashes into the wall" << endl;return;}if (rect[rob[ID].y + i][rob[ID].x] != 0){judge = true;cout << "Robot " << ID << " crashes into robot " << rect[rob[ID].y + i][rob[ID].x] << endl;return;}}rect[rob[ID].y][rob[ID].x] = 0;rob[ID].y += repeat;rect[rob[ID].y][rob[ID].x] = ID;}else{for (int i = 1; i <= repeat; i++){if (rob[ID].y - i < 1){judge = true;cout << "Robot " << ID << " crashes into the wall" << endl;return;}if (rect[rob[ID].y - i][rob[ID].x] != 0){judge = true;cout << "Robot " << ID << " crashes into robot " << rect[rob[ID].y - i][rob[ID].x] << endl;return;}}rect[rob[ID].y][rob[ID].x] = 0;rob[ID].y -= repeat;rect[rob[ID].y][rob[ID].x] = ID;}
}
void L(int ID, int repeat)//左转
{repeat %= 4;if (repeat == 1){if (rob[ID].direct == 'E')rob[ID].direct = 'N';else if (rob[ID].direct == 'S')rob[ID].direct = 'E';else if (rob[ID].direct == 'W')rob[ID].direct = 'S';elserob[ID].direct = 'W';}else if (repeat == 2){if (rob[ID].direct == 'E')rob[ID].direct = 'W';else if (rob[ID].direct == 'S')rob[ID].direct = 'N';else if (rob[ID].direct == 'W')rob[ID].direct = 'E';elserob[ID].direct = 'S';}else if (repeat == 3){if (rob[ID].direct == 'E')rob[ID].direct = 'S';else if (rob[ID].direct == 'S')rob[ID].direct = 'W';else if (rob[ID].direct == 'W')rob[ID].direct = 'N';elserob[ID].direct = 'E';}
}
void R(int ID, int repeat)//右转
{repeat %= 4;if (repeat == 1){if (rob[ID].direct == 'E')rob[ID].direct = 'S';else if (rob[ID].direct == 'S')rob[ID].direct = 'W';else if (rob[ID].direct == 'W')rob[ID].direct = 'N';elserob[ID].direct = 'E';}else if (repeat == 2){if (rob[ID].direct == 'E')rob[ID].direct = 'W';else if (rob[ID].direct == 'S')rob[ID].direct = 'N';else if (rob[ID].direct == 'W')rob[ID].direct = 'E';elserob[ID].direct = 'S';}else if (repeat == 3){if (rob[ID].direct == 'E')rob[ID].direct = 'N';else if (rob[ID].direct == 'S')rob[ID].direct = 'E';else if (rob[ID].direct == 'W')rob[ID].direct = 'S';elserob[ID].direct = 'W';}
}
int main()
{int K;scanf("%d",&K);while (K--){judge = false;scanf("%d%d",&A, &B);memset(rect, 0, sizeof(rect));int N, M;scanf("%d%d",&N, &M);for (int i = 1; i <= N; i++){cin >> rob[i].x >> rob[i].y >> rob[i].direct;rect[rob[i].y][rob[i].x] = i;//标志有机器人的位置}for (int i = 1; i <= M; i++)cin >> ist[i].ID >> ist[i].act >> ist[i].repeat;for (int i = 1; i <= M; i++){if (ist[i].act == 'F')F(ist[i].ID, ist[i].repeat);else if (ist[i].act == 'L')L(ist[i].ID, ist[i].repeat);elseR(ist[i].ID, ist[i].repeat);if (judge)break;}if (!judge)cout << "OK" << endl;}return 0;
}

POJ-2632:Crashing Robots(C++实现详细代码)相关推荐

  1. 模拟 POJ 2632 Crashing Robots

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

  2. POJ 1573 POJ 2632(两道有趣的Robot)实例

    /* ** POJ 2632 Crashing Robots ** Created by Rayn @@ 2014/04/16 ** 坑爹的模拟题,脑壳不清晰的就要被坑惨了 */ #include & ...

  3. HDU 2300 Crashing Robots

    Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...

  4. 教你C语言实现通讯录的详细代码

    本文详细讲解了C语言实现通讯录的方法,文中通过示例代码介绍的非常详细.对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 (一)实现思路 1.通讯录功能 添加好友,删除好友,查找好友,修改 ...

  5. 折叠式菜单 html,JQuery实现折叠式菜单的详细代码

    两种风格: 1:点菜单项,每个子菜单项都可显示 30秦甜甜_实训13-2_2_180701802230_18计算机2班 * { padding: 0; margin: 0; list-style: n ...

  6. ajax发送异步请求四个步骤,深入理解ajax异步请求的五个步骤(详细代码)

    在前端工作中,经常会用到ajax,其实很多人只知道ajax是异步请求,不知道应该如何用它,它的基本步骤有哪些,ajax请求过程是怎样的?接下来这篇文章就给大家介绍Ajax的请求步骤,以及ajax请求步 ...

  7. 开放下载!《15分钟打造你自己的小程序》(内附详细代码)

    简介: 零基础开发你自己的支付宝小程序,教程在手不迷路,从入门到精通,还有详细代码在里面哦~ <15分钟打造你自己的小程序>独家电子书上线啦!零基础开发你自己的支付宝小程序,手把手教你从入 ...

  8. java中nio怎么实现聊天,JAVA-NIO实现聊天室详细代码说明

    JAVA-NIO实现聊天室详细代码说明 JAVA-NIO实现聊天室详细代码说明 github源码:https://github.com/JolyouLu/JAVAIO.git src\main\jav ...

  9. python random函数_详细代码实战讲解:如何用 Python让自己变成天选之子

    今天为大家带来的内容是:详细代码讲解:如何用 Python让自己变成天选之子 话不多说直接上代码: 请大家猜一猜下面这段代码的运行效果: 你是不是以为这段代码运行以后,结果如下图所示? 但实际上,我可 ...

  10. php实现飘窗,JS实现网站图片飘窗效果,JavaScript悬浮广告(附详细代码)

    原标题:JS实现网站图片飘窗效果,JavaScript悬浮广告(附详细代码) JS实现网站图片飘窗效果,Java悬浮广告,郑州SEO提供以下代码,仅供参考: 飘窗效果-丁光辉博客(www.dinggu ...

最新文章

  1. 全面理解java内存模型_深入理解Java内存模型(八)——总结
  2. tensorflow model.compile() 示例
  3. 中职计算机说课稿三篇,2020精选中职计算机说课稿3篇(15页)-原创力文档
  4. Cisco pix或asa如何防止内网用户乱改ip配置案例
  5. 来一个可能防止恶意采集和爬虫的SH
  6. activity中获取fragment布局_安卓开发入门教程Fragment
  7. 面向对象编程(二):继承
  8. Springboot入门1
  9. oracle chinese_china.al32utf8,Oracle11g字符集更改为AL32UTF8
  10. php java node 并发,Node、PHP、Java 和 Go 服务端 I/O 性能PK
  11. mysql服务器磁盘空间耗尽_一次服务器磁盘空间不足导致的一系列问题
  12. 2008 r2 server sql 中文版补丁_Microsoft SQL Server 2008 R2 SP3补丁 64位 官方免费版
  13. 信道、频段带宽等术语简介
  14. vue中控制台报错[WDS] Disconnected的解决办法
  15. Java如何判断字符串中包含有全角,半角符号
  16. 阿卜杜拉国王科技大学的计算机,阿卜杜拉国王科技大学(KAUST)探索奖学金项目...
  17. 全球霸榜的Dell EMC VxRail,靠什么赢得超融合客户认可?
  18. 玩转基因组浏览器之初识IGV
  19. Unity中图集的制作与使用
  20. 同济七版高等数学(下册)习题及答案

热门文章

  1. VUE提示Gradient has outdated direction syntax
  2. 链家网深圳租房信息分析报告
  3. 小白初上手HTML+CSS 仿写小米官网logo动画
  4. spark编程ERROR01——java.lang.NullPointerException
  5. python tokenize()_Python tokenize-rt包_程序模块 - PyPI - Python中文网
  6. linux下root切换普通用户,linux之普通用户与root用户之间切换方法
  7. html怎样修改背景图片大小,css中如何设置背景图片的大小?
  8. matlab 花体字母,小论文格式模板.doc
  9. k8s入坑之报错(4)报错:repomod.xml signature could not be verified
  10. mysql localhost可以连接,输入ip地址连接访问被拒绝