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

Source

#include<cstdio>
#include<set>
#include<map>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
typedef long long LL;
#define MAXN 103
/*
模拟题,模拟机器人每一步操作
*/
struct node
{
int x,y,dir;
}a[MAXN]; int dx[] = {,-,,};
int dy[] = {,,-,};
int n,m,r,c,k;
int been[MAXN][MAXN];
inline int check(int x,int y)//0表示没碰撞 1碰墙 2碰人
{
if(x<=r&&x>&&y<=c&&y>)
{
if(!been[x][y])
return ;
else
return ;
}
return ;
}
int main()
{
scanf("%d",&k);
char dir[];
while(k--)
{
memset(been,,sizeof(been));
scanf("%d%d",&c,&r);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d%d%s",&a[i].y,&a[i].x,dir);
been[a[i].x][a[i].y] = i;
if(dir[]=='E') a[i].dir = ;
else if(dir[]=='S') a[i].dir = ;
else if(dir[]=='W') a[i].dir = ;
else a[i].dir = ;
}
int t1,t2;char act[];
bool f = false;
for(int i=;i<m;i++)
{
scanf("%d%s%d",&t1,act,&t2);
if(f) continue;
if(act[]=='F')
{
while(t2--)
{
been[a[t1].x][a[t1].y] = ;
a[t1].x += dx[a[t1].dir];
a[t1].y += dy[a[t1].dir];
int ans = check(a[t1].x,a[t1].y);
if(ans==)
been[a[t1].x][a[t1].y] = t1;
else if(ans==)
{
printf("Robot %d crashes into the wall\n",t1);
f = true;
break;
}
else
{
printf("Robot %d crashes into robot %d\n",t1,been[a[t1].x][a[t1].y]);
f = true;
break;
}
}
}
else if(act[]=='L')
{
while(t2--)
a[t1].dir = (a[t1].dir-+)%;
}
else
{
while(t2--)
a[t1].dir = (a[t1].dir+)%;
}
}
if(!f) printf("OK\n");
}
}

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

  1. Crashing Robots - poj 2632

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8352   Accepted: 3613 Description In ...

  2. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

  3. POJ 1008 简单模拟题

    e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...

  4. 模拟 POJ 2632 Crashing Robots

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

  5. poj 2632 Crashing Robots(模拟)

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

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

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

  7. Poj OpenJudge 百练 2632 Crashing Robots

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

  8. poj 2632 Crashing Robots

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

  9. POJ 2632:Crashing Robots

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

随机推荐

  1. moiezen

    这题是个随机化+二分裸题--------考场上居然没有想出来--想的出来就怪了吧 我们随机一下增加x的顺序,然后进行二分之前,看看这个x加完之后能不能更新答案,不能就不二分了.具题解所说,这个复杂度是 ...

  2. 转载使用 ContentObsever 拦截短信,获取短信内容

    在一些应用上,比如手机银行,QQ,微信等,很多时候我们都需要通过发送验证码到手机上,然后把验证码填上去,然后才能成功地继续去做下面一步事情. 而如果每次我们都要离开当前界面,然后去查收短信,记住验证码 ...

  3. 题解报告:hdu 2588 GCD(欧拉函数)

    Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ...

  4. JavaScript Json与Map互转以及Map对象的取值方式

    Json格式(Json字符串) : var json='{"name": "lily","age":"15"}' Map ...

  5. (2)HTML元素与属性(已入垃圾框)

    HTML元素 开始标签常被称为起始标签(opening tag),结束标签常称为闭合标签(closing tag) HTML 文档由嵌套的 HTML 元素构成 以上实例包含了七个 HTML 元素 &l ...

  6. Js上传图片并生成缩略图

    Js上传图片并显示缩略图的流程为 Js选择文件->Jquery上传图片->服务器接收图片流->存储图片->返回结果到Js端->显示缩略图 本文上传图片所用的Js库是aja ...

  7. 华硕(ASUS)X554LP笔记本重装win7后网卡和USB驱动问题的解决

    以前在其它笔记本上采用U盘克隆安装winxp系统非常顺利,各种硬件驱动能自动识别并安装. 手上有一台别人的华硕(ASUS)X554LP笔记本,原装win8.1,用不惯,想装个win7旗舰版. 照例去系 ...

  8. Memcached通信协议

    英文水平很烂,做梦都想着能把英语学习,可以使用一口流利的英文和洋鬼子交流,顺便忽悠下自己的同胞.没有地方学习英语,看还可以,网上有很多关于计算机的英文文献,写还行,说就完全不可能了.在以后的工作中慢慢 ...

  9. TASKCTL5.0日志乱码解决方案

    从大学毕业到现在,做了不少银行外包项目,数据类的项目基本都用到taskctl调度产品,一直习以为然,觉得调度产品都应该是这样的,所以也没觉得怎样,直到后来有两个外包项目没用taskctl调度工具,要接 ...

  10. Angular——作用域

    基本介绍 应用App是无法嵌套的,但是controller是可以嵌套的,每个controller都会对应一个模型(model)也就是$scope对象,不同层级的controller下的$scope遍产 ...