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 ...
随机推荐
- Java混乱的日志体系(logback)(转)
作为一名 Java 程序员,日常开发工作中肯定会接触日志系统,但是众多的框架,包括 Log4j.Log4j2.Logback.Slf4j.Apache Common logging 等等,引用的 ma ...
- 操作系统/etc/hosts文件配置
windows对应 C:\Windows\system32\drivers\etc\hosts linux: /etc/hosts Hosts - The static table lookup fo ...
- Android background tint颜色渲染
该篇文章主要是讲Android颜色渲染,首先先来看看PorterDuff,对绘图非常重要. PorterDuff的由来: 相信大多数人看到这个ProterDuff单词很奇怪了吧,这肿么个意思呢,然后就 ...
- vs2015安装VAssistX以后,去除中文注释会有红色下划线方法
---恢复内容开始--- 环境:Visual Studio 2015 问题:代码中出现中文后会带下划线,不舒服-----解决办法. 1.安装完Visual Assist X后会在VS2015的菜单栏出 ...
- cocos2d-x 2.2.0 图片选中聚焦 ,图片描边 CCClippingNode 实现
效果例如以下图 左边箭头是x方向翻转的.右边箭头有旋转和缩放action. 大概实现方法:用箭头作为遮罩层,底图是一个绘制的矩形,得到一个黄色箭头背景.在用schedule尾随要聚焦箭头动作.这个 ...
- crontab配置
1.命令功能 通过crontab 命令,我们可以在固定的间隔时间执行指定的系统指令或 shell script脚本.时间间隔的单位可以是分钟.小时.日.月.周及以上的任意组合.这个命令非常适合周期性的 ...
- 在elasticsearch里如何高效的使用filter
今天在做查询category的时候,遇到一个问题,查询出来的cateogry为food,fun的形式.但是我需要的只是food或者fun 不包含逗号. 开始想着在aggs后再做过滤,这样有些麻烦.遂在 ...
- 【Zookeeper】Zookeeper部署笔记
Zookeeper部署笔记 .上传zk安装包 .解压 .配置(先在一台节点上配置) .1添加一个zoo.cfg配置文件 $ZOOKEEPER/conf mv zoo_sample.cfg zoo.cf ...
- Python Requests post并将得到结果转换为json
Python Requests post并将得到结果转换为json 学习了:https://blog.csdn.net/sinat_28680819/article/details/70940325 ...
- 阻止右键菜单(阻止默认事件)&&跟随鼠标移动(大图展示)&&自定义右键菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...