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. 使用JS分页 <span> beta 3.0 完成封装的分页

    <html> <head> <title>分页</title> <style> #titleDiv{ width:500px; backgr ...

  2. win10下spark+Python开发环境配置

    Step0:安装好Java ,jdk Step1:下载好: Step2: 将解压后的hadoop和spark设置好环境变量: 在系统path变量里面+: Step3: 使用pip安装 py4j : p ...

  3. ibatis入门教程一

    这几天研究ibatis玩,参考一篇贴子进行安装配置:蓝雪森林 选择这个帖子来跟随配置是因为这个帖子看着比较干净,但是我仍旧在配置得过程中出现了好几个问题,所以我决定在这个帖子的基础上将更多细节加上,做 ...

  4. layer父页获取弹出层输入框里面的值

    主要是因为修改功能,原来页面填写数据如图 改为 其中点击填写明细弹出框 填写完毕后点击确认返回,同事这里因为她是存的多表,所以点击确认就直接保存数据了,改的这个功能原本保存是整体保存,我就不想改原来的 ...

  5. C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(249,5): error MSB6006: “CL.exe”已退出,代码为 -1073741515。

    解决: Add this to your PATH environment variables: C:\Program Files (x86)\Microsoft Visual Studio 11.0 ...

  6. P2668 斗地主 dp+深搜版

    题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4< ...

  7. C# datagrideview插件的使用

    private void btnLogin_Click(object sender, EventArgs e) { string txtUserName = this.txtUserName.Text ...

  8. MFC_2.9 使用变参函数

    使用变参函数 #include <stdio.h>​// 包含一个头文件,提供不定参数的宏#include <stdarg.h>​// 用于输出不定数量的整数值void pri ...

  9. CSS:div/img水平垂直居中

    div水平垂直居中方法一: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  10. 08Microsoft SQL Server 数据查询

    Microsoft SQL Server 数据查询 单表查询所有列 --查询所有行所有列 select all * from table; --查询不重复行的所有列 select distinct * ...