Crashing Robots
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
解释一下输入输出
这是一个机器人跑动的问题,给出机器人坐标和场地范围,以及行动指令;如果撞墙或者撞到其它机器人就停止(注意,输入要完成)
输入:4是4组数据
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
int len,high;
int a,b,j ;
struct node
{
int x;
int y ;
int dire;
} s[];
int judge(int k)
{
int i;
if(s[k].x > len||s[k].x< ||s[k].y>high||s[k].y<)
{
printf("Robot %d crashes into the wall\n",k);
return ;
}
for(i = ; i <= a ; i++)
{
if(i == k)
continue;
if(s[i].x == s[k].x&&s[i].y == s[k].y)
{
printf("Robot %d crashes into robot %d\n",k,i);
return ;
}
}
return ;
}
int main()
{
int n ;
cin>>n;
for(int i = ; i <= n ; i++)
{
cin>>len>>high;
cin>>a>>b ;
char dire ;
for(j = ; j <= a ; j++)
{
cin>>s[j].x>>s[j].y>>dire;
if(dire == 'N')
s[j].dire = ;
if(dire == 'W')
s[j].dire = ;
if(dire == 'S')
s[j].dire = ;
if(dire == 'E')
s[j].dire = ;
}
int num,repeat,flag = ;
char order ;
for(j = ; j <= b ; j++)
{
cin>>num>>order>>repeat ;
for(int h = ; h <= repeat ; h++ )//把这个放在外边是为了底下的左右指令时比较好处理
{
if(order == 'F')
{
if(s[num].dire == )
{
s[num].y++ ;
if(!judge(num))
{
flag = ;
break ;
}
}
else if(s[num].dire == )
{
s[num].x--;
if(!judge(num))
{
flag = ;
break ;
}
}
else if(s[num].dire == )
{
s[num].y--;
if(!judge(num))
{
flag = ;
break ;
}
}
else if(s[num].dire == )
{
s[num].x++ ;
if(!judge(num))
{
flag = ;
break ;
}
}
}
if(order == 'L')
s[num].dire = (+s[num].dire)% ;
if(order == 'R')
s[num].dire = (s[num].dire-+)%;
}
if(flag == )
break ;
}
if(j < b)
for(++j ; j <= b ; j++)
cin>>num>>order>>repeat ;
if(flag == )
printf("OK\n");
}
return ;
}
Crashing Robots的更多相关文章
- poj2632 Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9859 Accepted: 4209 D ...
- Crashing Robots(imitate)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8124 Accepted: 3528 D ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8340 Accepted: 3607 D ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- POJ2632——Crashing Robots
Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
- HDU 2300 Crashing Robots
Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...
随机推荐
- [置顶] 提高生产力:开源Java工具包Jodd(Java的”瑞士军刀”)
官方网站:http://jodd.org/ 下载地址:http://jodd.org/download/index.html Jodd=tools + ioc + mvc + db + aop + t ...
- [Reactive Programming] RxJS dynamic behavior
This lesson helps you think in Reactive programming by explaining why it is a beneficial paradigm fo ...
- [MODx] Solve cannot upload large file
If you also run into this problem, dont' worry, here is the solution for you. First: In Modx, go &qu ...
- hdu 4622 Reincarnation(后缀数组)
hdu 4622 Reincarnation 题意:还是比较容易理解,给出一个字符串,最长2000,q个询问,每次询问[l,r]区间内有多少个不同的字串. (为了与论文解释统一,这里解题思路里sa数组 ...
- Objective-C中的@Property详解
Objective-C中的@Property详解 @Property (属性) class vairs 这个属性有nonatomic, strong, weak, retain, copy等等 我把它 ...
- ipad itunes 恢复
http://jingyan.baidu.com/article/a3aad71aa58efbb1fa00967c.html http://act.feng.com/wetools/index.php ...
- 十个最好的Java性能故障排除工具
1.jconsole 是随着JDK 1.5而推出的.这是一个Java监测和管理控制台-JMX兼容的图形工具来监测Java虚拟机.它能够同时监测本地和远程的JVMs.详情可查看:jconsole工具介 ...
- iOS UI控件继承关系图
闲来无事,把UI控件的继承关系图整理下来,供自己和大家使用.
- python 学习笔记(二)两种方式实现第一个python程序
在交互模式下: 如果要让Python打印出指定的文字,可以用print语句,然后把希望打印的文字用单引号或者双引号括起来,但不能混用单引号和双引号: >>> print 'hello ...
- [总结]RTMP流媒体技术零基础学习方法
本文主要总结一些我在学习RTMP流媒体技术过程中积累的经验.也为后来学习RTMP流媒体技术的人们一个参考.本文力图从简到难,循序渐进的介绍RTMP流媒体技术的方方面面,先从应用说起,逐步深化剖析相关工 ...