Crashing Robots

Time Limit: 1000MS Memory Limit: 65536K

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


  • 题意就是给你一个图里面有很多机器人,每个机器人可以自身向左转或者右转(90度)或者向前走每个动作重复k次。输出机器人第一次撞到墙或者第一次撞到其他的机器人(机器人按照指令依次执行)。只输出第一次撞击,之后的不管。

  • 真的是反向建图日神仙,本来就是东西南北傻傻分不清,xy还反着输入,图的行列也是反着的。对于方向感不强的人来说简直是折磨啊。其实只要弄清楚方向,这个题很简单就可以过了。


#include<stdio.h>
#include<cstring> using namespace std;
struct roob
{
int x,y;
char dir[10];
} r[110];
bool r_pos[310][310];//标记图中机器人的位置
char Dir[10]= "0NESW";//用来计算机器人的转向
int n,m,x,y; void init()
{
memset(r_pos,0,sizeof(r_pos));
scanf("%d%d",&y,&x);//xy反着输入的
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
{
scanf("%d%d%s",&r[i].y,&r[i].x,&r[i].dir);
r_pos[r[i].x][r[i].y] = true;
}
} bool check(int w,int times)//机器人w向前走times步
{
roob now = r[w];
int x1 = now.x;
int y1 = now.y;
r_pos[x1][y1] = false;//走了之后记得取消标记
if(now.dir[0] == 'N')
{
for(int i=1; i<=times; i++)
{
int x2 = x1+i;
if(r_pos[x2][y1])
{
for(int i=1; i<=n; i++)
if(r[i].x == x2 && r[i].y == y1)
{
printf("Robot %d crashes into robot %d\n",w,i);
return true;
}
}
}
x1 += times;
}
else if(now.dir[0] == 'S')
{
for(int i=1; i<=times; i++)
{
int x2 = x1-i;
if(r_pos[x2][y1])
{
for(int i=1; i<=n; i++)
if(r[i].x == x2 && r[i].y == y1)
{
printf("Robot %d crashes into robot %d\n",w,i);
return true;
}
}
}
x1 -= times;
}
else if(now.dir[0] == 'E')
{
for(int i=1; i<=times; i++)
{
int y2 = y1+i;
if(r_pos[x1][y2])
{
for(int i=1; i<=n; i++)
if(r[i].x == x1 && r[i].y == y2)
{
printf("Robot %d crashes into robot %d\n",w,i);
return true;
}
}
}
y1 += times;
}
else if(now.dir[0] == 'W')
{
for(int i=1; i<=times; i++)
{
int y2 = y1-i;
if(y2 < 1)
continue;
if(r_pos[x1][y2])
{
for(int i=1; i<=n; i++)
if(r[i].x == x1 && r[i].y == y2)
{
printf("Robot %d crashes into robot %d\n",w,i);
return true;
}
}
}
y1 -= times;
}
if(x1<1 || y1<1 || x1>x || y1>y)//走到地图外面去了
{
printf("Robot %d crashes into the wall\n",w);
return true;
}
r_pos[x1][y1] = true;//到达新的地点被标记
r[w].x = x1;
r[w].y = y1;
return false;
} void solve()
{
bool flag = false;//标记是否发生第一次撞击
while(m--)
{
int w,times;
char d[10];
scanf("%d%s%d",&w,d,&times);
if(flag)//发生第一次撞击之后都不用管了
continue;
int temp2;
if(r[w].dir[0] == 'N')
temp2 = 1;
else if(r[w].dir[0] == 'E')
temp2 = 2;
else if(r[w].dir[0] == 'S')
temp2 = 3;
else if(r[w].dir[0] == 'W')
temp2 = 4;
if(d[0] == 'F')
flag = check(w,times);
else if(d[0] == 'L')//向左转的计算
{
times %= 4;
temp2 -= times;
if(temp2 < 1)
temp2 += 4;
r[w].dir[0] = Dir[temp2];
}
else if(d[0] == 'R')//向右转的计算
{
times %= 4;
temp2 += times;
if(temp2 > 4)
temp2 %= 4;
r[w].dir[0] = Dir[temp2];
}
}
if(!flag)
printf("OK\n");
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
init();
solve();
}
return 0;
}

POJ:2632-Crashing Robots的更多相关文章

  1. 模拟 POJ 2632 Crashing Robots

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

  2. Poj OpenJudge 百练 2632 Crashing Robots

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

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

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

  4. poj 2632 Crashing Robots

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

  5. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

  6. poj 2632 Crashing Robots(模拟)

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

  7. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

  8. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  9. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  10. POJ 2632:Crashing Robots

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

随机推荐

  1. docker 的目录问题

    今天在使用Dockerfile制作镜像的时候,使用命令 :COPY aaa.sql /usr/test 下时, 总是报错 “INFO[0001] stat /var/lib/docker/aufs/m ...

  2. 关于float和double类型能表示的数据范围和精度分析

    来自教材<计算机组成原理>p16 float:6--7位 double:15--16位 意思就是double类型的数据,你确实能表达出很大的数字,但是其只有15位是精确的. 1.计算机中, ...

  3. Zookeeper+websocket实现对分布式服务器的实时监控(附源码下载)

    ​ 我就是个封面 Zookeeper简介 Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统. 简单来说就是一个Zookeeper注册同步中心,内部结构为一个树形目录,每个节点上 ...

  4. springmvc的DispatcherServlet源码——doDispatch方法解析

    DispatcherServlet的doDispatch方法主要用作职责调度工作,本身主要用于控制流程,主要职责如下: 1.文件上传解析,如果请求类型是multipart将通过MultipartRes ...

  5. JSONModel 简单例子

    // ProductModel.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All righ ...

  6. JAVA基础之基本类型包装类、System类、Math类、Arrays类及大数据运算

    个人理解: 为了方便运算及调用一些方法,我们需要将基本类型的数值转换为对象:不过转换的时候需要特别注意好它们的类型到底是什么,需要调用方法的类名是哪个!特别注意是Byte常量池的相关问题(==):gc ...

  7. Java基础:(一)数据类型

    一.包装类型 基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成. 八个基本类型:boolean/1:byte/8:char/16:short/16:int/32: ...

  8. Java运算符、引用数据类型、流程控制语句

    1运算符 1.1算术运算符 运算符是用来计算数据的符号. 数据可以是常量,也可以是变量. 被运算符操作的数我们称为操作数. 算术运算符最常见的操作就是将操作数参与数学计算: 运算符 运算规则 范例 结 ...

  9. ae(ArcEngine) java swing开发入门系列(2):ae的类型转换和Proxy类说明

    做过C#版ae的都知道,操作同一个“对象”,用他的不同功能要转换到相应的接口,但java版有时不能直接做类型转换 例如下图在C#是可以的 但在java不行,这样转会报错,看IFeatureClass的 ...

  10. 【extjs6学习笔记】0.1 准备:基础概念(02)

    Ext 类 Ext 是一个全局单例的对象,在 Sencha library 中它封装了所有的类和许多实用的方法.许多常用的函数都定义在 Ext 对象里.它还提供了像其他类中一些频繁使用的方法的快速调用 ...