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. [洛谷3796]【模板】AC自动机(加强版)

    题目大意: 给定$n(n\leq150)$个模式串$p_i(|p_i|\le70)$和一个$t(|t|\le10^6)$,求$t$中被匹配次数最多的$p_i$. 思路: AC自动机.匹配时记录一下匹配 ...

  2. noip2017集训测试赛(十一)Problem C: 循环移位

    题面 Description 给定一个字符串 ss .现在问你有多少个本质不同的 ss 的子串 t=t1t2⋯tm(m>0)t=t1t2⋯tm(m>0) 使得将 tt 循环左移一位后变成的 ...

  3. 关于poedit打开po文件乱码的问题

    由于poedit打开po文件时,无法识别译文使用的何种编码,因此需要在po文件头部加上以下代码: msgid "" msgstr "" "Plural ...

  4. tc: 模拟网络异常的工具-----------鸟窝

    http://colobu.com/2017/04/21/tc-introduction/

  5. debian下QT4编程环境的建立

    转:http://moosewoler.blog.163.com/blog/static/6986605200801013442336/ QT是一款跨平台的C++编程framework.QT的主要特性 ...

  6. mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构

    原文:http://blog.csdn.net/oh_mourinho/article/details/51463413 创建maven项目 <span style="font-siz ...

  7. nginx -- 启动, 重启, 关闭

    Nginx的启动.停止与重启 重启:  nginx -s reload 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin] ...

  8. 数据库学习--wildfly配置postgreSQL数据源

    前言 实验室最近在做一个物品管理系统的小项目,其中涉及到postgreSQL的使用,刚开始部署到wildfly服务器上时遇到了若干问题,终于在导师的讲解下大体上明白了 ,特此记录分享学习一下. 配置数 ...

  9. leetcode题解:Valid Palindrome(判断回文)

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  10. Linux alias理解及设置

    1.alias简介 Linux alias 是命令的一种别称,输入 alias 可以看到像下面这样的结果: alias l.='ls -d .* --color=auto' alias ll='ls ...