题目链接:

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

题目大意:

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

思路:

注意细节,直接模拟

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + ;
const int INF = << ;
int dir[][] = {,,,,-,,,-};
int T, n, m;
struct node
{
int x, y, dir;
};
node a[maxn];
map<char, int>M;
int Map[][];
int main()
{
cin >> T;
int c1, c2;
M['E'] = ;
M['N'] = ;
M['W'] = ;
M['S'] = ;
while(T--)
{
cin >> n >> m;
cin >> c1 >> c2;
char c;
memset(Map, , sizeof(Map));
memset(a, , sizeof(a));
for(int i = ; i <= c1; i++)
{
cin >> a[i].x >> a[i].y >> c;
a[i].dir = M[c];
Map[a[i].x][a[i].y] = i;
}
int flag = , ansid1, ansid2;
for(int i = ; i <= c2; i++)
{
int id, tot;
cin >> id >> c >> tot;
if(flag)continue;
if(c == 'L')
{
a[id].dir += tot;
a[id].dir %= ;
}
else if(c == 'R')
{
a[id].dir -= tot;
a[id].dir = ((a[id].dir % ) + ) % ;
}
else if(c == 'F')
{
Map[a[id].x][a[id].y] = ;
for(int i = ; i <= tot; i++)
{
//cout<<a[id].x<<" "<<a[id].y<<" "<<a[id].dir<<endl;
a[id].x += dir[a[id].dir][];
a[id].y += dir[a[id].dir][]; if(a[id].x <= || a[id].x > n || a[id].y <= || a[id].y > m)
{
flag = ;
ansid1 = id;
break;
}
else if(Map[a[id].x][a[id].y])
{
flag = ;
ansid1 = id;
ansid2 = Map[a[id].x][a[id].y];
}
if(flag)break;
}
Map[a[id].x][a[id].y] = id;
}
}
if(!flag)cout<<"OK"<<endl;
else if(flag == )
cout<<"Robot "<<ansid1<<" crashes into the wall"<<endl;
else cout<<"Robot "<<ansid1<<" crashes into robot "<<ansid2<<endl;
}
return ;
}

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. thinkphp3.2-更改控制器名后找不到相应的表?报1146的错

    用tp在做着自己的小系统的时候,明明在刚才还是能好好地查到表的,在Service用了'D'方法连自己数据库的表,只是更改了自己的控制器名,却报错了... 我就纳闷了,虽然我的控制器和Service用的 ...

  2. 【CSS】 CSS的一些应用实例和参考

    css 一些应用实例 基本抄自http://www.w3school.com.cn/css/css_align.asp ..把这些知识消化吸收然后以自己的话来解释一下 ■ 对齐 ●  用margin属 ...

  3. 蚂蚁金服安全实验室首次同时亮相BlackHat Asia 以及CanSecWest国际安全舞台

    近期,蚂蚁金服巴斯光年安全实验室(以下简称AFLSLab)同时中稿BlackHat Asia黑帽大会的文章以及武器库,同时在北美的CanSecWest安全攻防峰会上首次中稿Android安全领域的漏洞 ...

  4. Spring Boot 2.0(五):Docker Compose + Spring Boot + Nginx + Mysql 实践

    我知道大家这段时间看了我写关于 docker 相关的几篇文章,不疼不痒的,仍然没有感受 docker 的便利,是的,我也是这样认为的,I know your felling . 前期了解概念什么的确实 ...

  5. java排序算法(三):堆排序

    java排序算法(三)堆排序 堆积排序(HeapSort)是指利用堆积树这种结构所设计的排序算法,可以利用数组的特点快速定位指定索引的元素.堆排序是不稳定的排序方法.辅助空间为O(1).最坏时间复杂度 ...

  6. touch事件过程

    local function onTouchBegan(touch, event) local point = touch:getLocation() --获取touch位置, 基于openGL坐标 ...

  7. Android中的layout_gravity和gravity的区别

    在Android的布局中,除了padding和margin容易弄混之外,还有layout_gravity和gravity.按照字面意思来说,layout_gravity就是相对于layout来设置的. ...

  8. hibernate框架学习笔记5:缓存

    缓存不止存在与程序中,电脑硬件乃至于生活中都存在缓存 目的:提高效率 比如IO流读写字节,如果没有缓存,读一字节写一字节,效率低下 hibernate中的一级缓存:提高操作数据库的效率 示例: 抽取的 ...

  9. Beta Scrum博客集

    听说 Beta Scrum Day 1

  10. Beta冲刺NO.3

    Beta冲刺 第三天 1. 昨天的困难 1.昨天的困难主要集中在对Ajax的使用上,不熟悉这种语法,所以也就浪费了时间,导致昨天的批量删除没有完全完成. 2.由于之前的网页构造style很乱,导致修改 ...