Crashing Robots - poj 2632
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8352 | Accepted: 3613 |
Description
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 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
- 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的更多相关文章
- Crashing Robots POJ 2632 简单模拟
Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- POJ 2632:Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8424 Accepted: 3648 D ...
- Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8340 Accepted: 3607 D ...
- 模拟 --- Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7394 Accepted: 3242 D ...
随机推荐
- php程序无法使用localhost连接数据库解决方法(linux)
php程序无法使用localhost连接数据库解决方法(linux) 出现这种情况是因为PHP无法正确获取mysql.sock 在php.ini文件中指定即可解决问题. 修改如下: 找到 mysql. ...
- 细说JavaScript对象(3):hasOwnProperty
判断一个属性是定义在对象本身而不是继承自原型链,我们需要使用从 Object.prototype 继承而来的 hasOwnProperty 方法. hasOwnProperty 方法是 JavaScr ...
- Delphi 使用 SPcomm 调试串口程序出现总是在程序断开的时候,才发送指令的问题。
问题如上, 在与嵌入式程序串口程序通讯的时候, 总是出现如上问题, 造成的原因把下面的True改成false就可以了. 下图Spcomm的属性页,几个True全改成False再试试
- SpringBoot 框架整合webservice
spring boot集成web service框架 题记: 本篇博客讲的spring boot如何集成 spring web service,如果您想用Apache CXF集成,那么可能不适合您.为 ...
- [置顶]
kubernetes-kubectl命令说明
kubectl kubectl controls the K8S cluster manager. Find more information at https://github.com/K8S/K8 ...
- 获得Oracle当前日期的年或月的第一天和最后一天
.当前日期的年份第一天和最后一天 第一天 select trunc(sysdate,'y') FROM DUAL; select trunc(sysdate,'yy') FROM DUAL; sele ...
- Java高级特性—消息队列
1)什么是jms JMS即Java消息服务(Java Message Service)应用程序接口是一个Java平台中关于面向消息中间件(MOM)的API. 它便于消息系统中的Java应用程序进行消息 ...
- 批量删除Redis中的key
bin/redis-cli -h 192.168.46.151 -p 6379 keys "rulelist*" | xargs bin/redis-cli -h 192.168 ...
- 2017.5.27 使用propagation实现:根据参数决定是否需要事务管理
1.功能描述 要实现rest接口:POST ***/entry,其中参数中有action参数. 当action=rollback时,批量新增出错时需要回滚. 当action!=rollback时,批量 ...
- MSSQL注入SA权限不显错模式下的 入 侵
一般新手扫到不显错的SA(systemadmin)的注入点时,虽然工具能猜表列目录但还是很麻烦有的人就直接放弃了,今天我给大家演示下如何利用.方法很简单大家看操作. 我这里使用的是 火狐的插件提交参数 ...