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 ...
随机推荐
- Oracle触发器简单入门记录
写在前面: 最近,老项目新增了日报优化的需求,丽姐让我用触发器去实现当数据插入或者更新的时候,实现对日报表数据更新操作.嗯嗯嗯呢,之前学习数据库的时候,有碰到过触发器,但都是一跳而过,也没怎么去真正的 ...
- iOS 代理 重定向消息 forwardInvocation
今天简单研究一下iOS的重定向消息forwardInvocation: 首先看看Invocation类: @interface NSInvocation : NSObject { @private _ ...
- rpm安装、卸载、升级、查询和验证
RPM 的全称为Redhat Package Manager ,是由Redhat 公司提出的,用于管理Linux 下软件包的软件.Linux 安装时,除了几个核心模块以外,其余几乎所有的模块均通过RP ...
- 【spring boot】15.spring boot项目 采用Druid数据库连接池,并启用druid监控功能
在http://www.cnblogs.com/sxdcgaq8080/p/9039442.html的基础上,来看看spring boot项目中采用Druid连接池. GitHub地址:示例代码 == ...
- html 打印代码,支持翻页
ylbtech_html_print html打印代码,支持翻页 <html> <head> <meta name=vs_targetSchema content=&qu ...
- Filter及FilterChain的详解
一.Filter的介绍及使用 什么是过滤器? 与Servlet相似,过滤器是一些web应用程序组件,可以绑定到一个web应用程序中.但是与其他web应用程序组件不同的是,过滤器是"链&quo ...
- 2017.4.10 spring-ldap官方文档学习
官网:http://www.springframework.org/ldap 官方文档及例子(重要):http://docs.spring.io/spring-ldap/docs/2.1.0.RELE ...
- 转:100.64. 开头IP地址问题
100.64. 开头IP地址问题 姚洪楼 发表于 学习备忘录 分类,标签: 电信 08二月2015 0 之前调试过一个路由器在成功设置DDNS的情况下外网依旧无法访问的情况,当时没有多想什么,一直以为 ...
- JavaSE入门学习18:Java面向对象之多态
一Java多态 多态是同一个行为具有多个不同表现形式或形态的能力. 多态性是对象多种表现形式的体现.比方我们说"宠 物"这个对象.它就有非常多不同的表达或实现,比方有小猫.小狗.蜥 ...
- Web 目录枚举与遍历漏洞解决
"目录枚举漏洞"解决方法 一.名词解释 网站目录枚举漏洞:指黑客利用非法攻击手段扫描符合"8.3"命名原则的目录与文件. 二.验证工具:scanner-comp ...