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. 视图解析器InternalResourceViewResolver在什么情况下需要配置?在什么情况下不需要配置?

    如果路径名是逻辑名的话,必须配置 -------------- 相对路径,即逻辑名称如果路径名是真实名的话,可选配置 若是绝对路径,则不用配置,即真实名称 注:试一下逻辑名和真实名的例子*****有用 ...

  2. 每天学点Linux命令之Linux-Shell中的数据重定向与管道命令

    在Linux shell中, 数据重定向使用 > < 符号,管道命令使用 | 符号链接前后两个命令. 具体区别如下: 数据重定向 1.(>): 左侧应该有标准输出 > 右侧只能 ...

  3. 网页添加qq咨询

    <style>.box{ width:130px; height:150px; position:fixed; right:0px; top:30%; z-index:999; borde ...

  4. LN : leetcode 513 Find Bottom Left Tree Value

    lc 513 Find Bottom Left Tree Value 513 Find Bottom Left Tree Value Given a binary tree, find the lef ...

  5. Farseer.net轻量级开源框架 入门篇:修改数据详解

    导航 目   录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 添加数据详解 下一篇:Farseer.net轻量级开源框架 入门篇: 删除数据详解 ...

  6. Spring框架系列(九)--MyBatis面试题(转载)

    1.什么是Mybatis? 1.Mybatis是一个半ORM(对象关系映射)框架,它内部封装了JDBC,开发时只需要关注SQL语句本身,不需要花费精力去处理加载驱动.创建 连接.创建statement ...

  7. ThinkPHP---TP功能类之邮件

    [一]概论 (1)简介: 这里说的邮件不是平时说的email邮件(邮件地址带有@符号的),而是指的一般论坛网站的站内信息,也叫私信或者pm(private message私信) [二]站内信案例 (1 ...

  8. 查询条件中,不进sql语句 也不进后台bug

    前端代码:本来代码中少写了value="1",后来加上value值之后,可以正常进方法 <div class="row"> <label cl ...

  9. 2019西安多校联训 Day3

    试题链接:http://www.accoders.com/contest.php?cid=1895    考试密码请私信; 特别鸣谢:zkc奆佬帮助我优化本篇题解(语言表达方面) T1 显然二分求解的 ...

  10. iOS中NSAttributedString的使用--对关键字着色,以及处理html实例

    1,最近项目中用到了一个功能,一个很好的功能.就是用户在搜索的时候,搜索结果出来后对你输入的关键字进行红色标记.这样用户就很请楚的看到自己输入什么后会出现什么样子的结果.还有一个功能是,现在有一段文字 ...