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

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
 #include <iostream>
#include<string.h>
using namespace std; int main() { int K=;
int ew,ns;
int robots_num;
int instruction;
//读取记录机器人的位置
int robots_posx[];
int robots_posy[];
int robots_to[];
//读取记录对机器人的操作
int ins_rob[];
char ins_op[];
int ins_rep[];
//记录所有机器人的位置
int pos[][];
cin>>K;
//flag 记录状态 -1 Ok;0 撞到墙;其他 撞到机器人的编号
int flag=-;
int rob_n;
for(int i=;i<K;i++){
flag=-;
rob_n=;
memset(pos,,sizeof(int)*);
cin>>ew>>ns>>robots_num>>instruction;
for(int j=;j<robots_num;j++){
char tmp;
cin>>robots_posx[j]>>robots_posy[j];
pos[robots_posy[j]-][robots_posx[j]-]=j+;
cin>>tmp;
switch(tmp){
case('N'):
robots_to[j]=;
break;
case('E'):
robots_to[j]=;
break;
case('S'):
robots_to[j]=;
break;
case('W'):
robots_to[j]=;
break;
}
}
for(int j=;j<instruction;j++){
cin>>ins_rob[j];
cin>>ins_op[j];
cin>>ins_rep[j];
}
for(int j=;j<instruction;j++){
int rob=ins_rob[j]-;
char op=ins_op[j];
if(op=='L')
robots_to[rob]=(robots_to[rob]+(-ins_rep[j]%))%;
if(op=='R')
robots_to[rob]=(robots_to[rob]+ins_rep[j])%;
if(op=='F'){
int rep=ins_rep[j];
pos[robots_posy[rob]-][robots_posx[rob]-]=;
int tow=robots_to[rob];
if(tow==){
for(int k=;k<rep;k++){
robots_posy[rob]++;
if(robots_posy[rob]>ns){
flag=;
rob_n=rob+;
break;
}else if(pos[robots_posy[rob]-][robots_posx[rob]-]!=){
flag=pos[robots_posy[rob]-][robots_posx[rob]-];
rob_n=rob+;
break;
}
}
}else if(tow==){
for(int k=;k<rep;k++){
robots_posx[rob]++;
if(robots_posx[rob]>ew){
flag=;
rob_n=rob+;
break;
}else if(pos[robots_posy[rob]-][robots_posx[rob]-]!=){
flag=pos[robots_posy[rob]-][robots_posx[rob]-];
rob_n=rob+;
break;
}
}
}else if(tow==){
for(int k=;k<rep;k++){
robots_posy[rob]--;
if(robots_posy[rob]<){
flag=;
rob_n=rob+;
break;
}else if(pos[robots_posy[rob]-][robots_posx[rob]-]!=){
flag=pos[robots_posy[rob]-][robots_posx[rob]-];
rob_n=rob+;
break;
}
}
}else if(tow==){
for(int k=;k<rep;k++){
robots_posx[rob]--;
if(robots_posx[rob]<){
flag=;
rob_n=rob+;
break;
}else if(pos[robots_posy[rob]-][robots_posx[rob]-]!=){
flag=pos[robots_posy[rob]-][robots_posx[rob]-];
rob_n=rob+;
break;
}
}
}
if(flag!=-)
break;
pos[robots_posy[rob]-][robots_posx[rob]-]=rob+;
} }
if(flag==-)
cout<<"OK"<<endl;
else if(flag==)
cout<<"Robot "<<rob_n<<" crashes into the wall"<<endl;
else
cout<<"Robot "<<rob_n<<" crashes into robot "<<flag<<endl;
}
return ;
}

Crashing Robots - poj 2632的更多相关文章

  1. Crashing Robots POJ 2632 简单模拟

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...

  2. 模拟 POJ 2632 Crashing Robots

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

  3. Poj OpenJudge 百练 2632 Crashing Robots

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

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

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

  5. poj 2632 Crashing Robots

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

  6. poj 2632 Crashing Robots(模拟)

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

  7. POJ 2632:Crashing Robots

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

  8. Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8340   Accepted: 3607 D ...

  9. 模拟 --- Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7394   Accepted: 3242 D ...

随机推荐

  1. [BZOJ 1800] 飞行棋

    Link: BZOJ 1800 传送门 Solution: $O(n^4)$…… Code: #include <bits/stdc++.h> using namespace std; ] ...

  2. Bean的实例化--静态工厂

    1,创建实体类User package com.songyan.demo1; /** * 要创建的对象类 * @author sy * */ public class User { private S ...

  3. 集合框架(04)HashMap扩展知识

    Map扩展知识 map集合被使用是具备映射关系 “bigclass”: “001”, ”zhangsan” “002”, ”lisi” “smallclass” : ”001”, “wangwu” : ...

  4. sql 分组后按时间降序排列再取出每组的第一条记录

    原文:sql 分组后按时间降序排列再取出每组的第一条记录 竞价记录表: Aid 为竞拍车辆ID,uid为参与竞价人员ID,BidTime为参与竞拍时间 查询出表中某人参与的所有车辆的最新的一条的竞价记 ...

  5. JAVA常见算法题(十五)

    package com.xiaowu.demo; /** * * 输入三个整数x,y,z,请把这三个数由小到大输出. * * @author WQ * */ public class Demo15 { ...

  6. Google Xpath Helper

    下载方法: 1. 访问http://chrome-extension-downloader.com/ 2. 把https://chrome.google.com/webstore/detail/xpa ...

  7. centos7 mongodb3.2与3.4版本安装(转)

    一.安装环境及配置yum vi /etc/yum.repos.d/mongodb-org-3.2.repo [mongodb-org-3.2] name=MongoDB Repository base ...

  8. ElasticSearch 排序

    1.相关性排序 ElasticSearch为了按照相关性来排序,需要将相关性表示为一个数值,在 Elasticsearch 中, 相关性得分 由一个浮点数进行表示,并在搜索结果中通过 _score 参 ...

  9. Hadoop之HDFS详解

    1.HDFS的概念和特性 它是一个文件系统,其次是分布式的 重要特性: 1).HDFS中的文件在物理上是分块存储(block),新版默认128M 2).客户端通过路径来访问文件,形如:hdfs://n ...

  10. 数据库中存在0,1,2.....或者1,null,2 排序时让0或者null在最后的sql语句

     select * from yryz_products_t order by isnull(sort),sort;     select * from yourtable order by cast ...