Crashing Robots
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7799   Accepted: 3388

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 简单的模拟
应用时:15min
实际用时:1h40min
问题:碰撞的先后次序
#include<cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int A,B,n,m;
int robot[][];
char rbuff[];
int dir[];
const int dx[]={,,,-};
const int dy[]={,,-,};
int action[][];
int tx,ty;
int ansr;
bool between(int aim,int gap){
int sx=robot[gap][];
int sy=robot[gap][];
int mingx=min(sx,tx);
int maxgx=max(sx,tx);
int mingy=min(sy,ty);
int maxgy=max(sy,ty);
int ax=robot[aim][];int ay=robot[aim][];
if(ax>=mingx&&ax<=maxgx&&ay>=mingy&&ay<=maxgy){
if(ansr==)ansr=aim;
else {
if(abs(robot[ansr][]-sx)>=abs(ax-sx)&&abs(robot[ansr][]-sy)>=abs(ay-sy)){
ansr=aim;
}
}
return true;
}
return false;
}
void solve(){
ansr=;
for(int i=;i<m;i++){
int rob=action[i][];
int rep=action[i][];
if(action[i][]==){
robot[rob][]=(robot[rob][]+-rep%)%;
}
else if(action[i][]==){
robot[rob][]=(robot[rob][]+rep%)%;
}
else{
bool fl=false;
tx=robot[rob][]+rep*dx[robot[rob][]];
ty=robot[rob][]+rep*dy[robot[rob][]];
for(int j=;j<=n;j++){
if(j==rob)continue;
if(between(j,rob)){
fl=true;
}
}
if(fl){
printf("Robot %d crashes into robot %d\n",rob,ansr);return ;
}
if(tx<||tx>A||ty<||ty>B){
printf("Robot %d crashes into the wall\n",rob);return ;
}
robot[rob][]=tx;
robot[rob][]=ty;
}
}
puts("OK");
} int main(){
#ifndef ONLINE_JUDGE
freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
dir['N']=;dir['E']=;dir['S']=;dir['W']=;
dir['L']=;dir['R']=;dir['F']=;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&A,&B,&n,&m);
for(int i=;i<=n;++i){
scanf("%d%d%s",robot[i],robot[i]+,rbuff);
robot[i][]=dir[rbuff[]];
}
for(int i=;i<m;i++){
scanf("%d%s%d",action[i],rbuff,action[i]+);
action[i][]=dir[rbuff[]];
}
solve();
}
return ;
}

快速切题 poj2632的更多相关文章

  1. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  2. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  3. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  4. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  5. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  6. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  7. 快速切题 sgu117. Counting 分解质因数

    117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...

  8. 快速切题 sgu116. Index of super-prime bfs+树思想

    116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...

  9. 快速切题 sgu115. Calendar 模拟 难度:0

    115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...

随机推荐

  1. CSS实现三角形、梯形、平行四边形、圆形、椭圆形、对话框、自适应正方形

    本文篇幅较长,希望能坚持看完,转载请注明出处,如果觉得好文请给个赞吧 CSS实现梯形 CSS实现三角形和梯形主要是依靠border是梯形的特性来做的,有点像相框的那种感觉. 首先我们先给一个正方形设置 ...

  2. 某模拟题(USACO部分题+noip2005部分题)

    题目描述 农场上有N(1 <= N <= 50,000)堆草,放在不同的地点上.FJ有一辆拖拉机,也在农场上.拖拉机和草堆都表示为二维平面上的整数坐标,坐标值在1..1000的范围内.拖拉 ...

  3. VC++ 利用CreateFile、ReadFile和WriteFile实现CopyFile

    1. CreateFile:这是一个多功能的函数,可打开或创建以下对象,并返回可访问的句柄:控制台,通信资源,目录(只读打开),磁盘驱动器,文件,邮槽,管道. 参照:http://www.cppblo ...

  4. POJ 1751 Highways(最小生成树&Prim)题解

    思路: 一开始用Kruskal超时了,因为这是一个稠密图,边的数量最惨可能N^2,改用Prim. Prim是这样的,先选一个点(这里选1)作为集合A的起始元素,然后其他点为集合B的元素,我们要做的就是 ...

  5. js中this关键字的使用

    <script> //题目一:理解r1与r2的输出 function addFactory(){ var adder = 5; return function(data){ adder + ...

  6. 【jdk源码分析】jdk8的ArrayList初始化长度为0

    先看结果 用的是反射获取elementData底层数组的长度 查看源码 无参构造函数没有了this.size = 10; 图1 图2 图3 图4 java的基本数据类型默认值 所以无参构造时长度为0 ...

  7. ThreadPoolExecutor执行过程分析

    ThreadPoolExecutor public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTi ...

  8. WPF基础学习笔记整理 (四) 布局

    WPF使用的是容器(container)进行布局: WPF窗口(Window类型)只能包含单个元素,故为了放置多个元素并增强界面效果,引入了容器: WPF布局容器都派生自System.Windows. ...

  9. JavaScript页面跳转的一些实现方法

    第一种 <script language=”javascript” type=”text/javascript”> window.location.href=”login.jsp?back ...

  10. django查询操作

    查询操作是Django的ORM框架中最重要的内容之一.我们建立模型.保存数据为的就是在需要的时候可以查询得到数据.Django自动为所有的模型提供了一套完善.方便.高效的API,一些重要的,我们要背下 ...