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
解释一下输入输出
这是一个机器人跑动的问题,给出机器人坐标和场地范围,以及行动指令;如果撞墙或者撞到其它机器人就停止(注意,输入要完成)

输入:4是4组数据

5 4 是场地范围
2 2  2个机器人,两个指令;
1 1 E    1,1 是坐标,E是机器人此时面临的方向;
1 F 7    1是机器人序号   F  是指令   7是执行次数
关于指令
          F: 直走;
          L:左转90度;
          R:右转90度;
 
 
下面的代码是我同学的  他写的比我的简洁
 #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的更多相关文章

  1. poj2632 Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9859   Accepted: 4209 D ...

  2. Crashing Robots(imitate)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8124   Accepted: 3528 D ...

  3. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  4. Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8340   Accepted: 3607 D ...

  5. poj 2632 Crashing Robots

    点击打开链接 Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6655   Accepted: ...

  6. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  7. POJ2632——Crashing Robots

    Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...

  8. POJ 2632 Crashing Robots (坑爹的模拟题)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6599   Accepted: 2854 D ...

  9. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

  10. HDU 2300 Crashing Robots

    Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...

随机推荐

  1. 手把手教你在ubuntu下创建桌面快捷方式

    习惯使用windows的朋友来说创建桌面快捷方式简直就是so easy, 鼠标右键点击文件-->选择发送桌面快捷方式.就OK了.对于ubuntu下该如何创建桌面快捷方式呢?以下以创建eclips ...

  2. android tips—启动Emergency call拨号盘

    Intent intent = new Intent(); intent.setAction("com.android.phone.EmergencyDialer.DIAL"); ...

  3. Java中泛型 问号的作用

    这是jdk1.5泛型的典型应用: 第一种写法,叫做使用泛型方法:    public <T extends Object> void thisIsT(List <T> list ...

  4. Java基础知识强化之集合框架笔记36:List练习之键盘录入多个数据在控制台输出最大值

    1. 键盘录入多个数据,以0结束,要求在控制台输出这多个数据中的最大值 分析: •  创建键盘录入数据对象 •  键盘录入多个数据,我们不知道多少个,所以用集合存储 •  以0结束,这个简单,只要键盘 ...

  5. Android(java)学习笔记206:利用开源SmartImageView优化网易新闻RSS客户端

    1.我们自己编写的SmartImageView会有很多漏洞,但是我们幸运的可以在网上利用开源项目的,开源项目中有很多成熟的代码,比如SmartImageView都编写的很成熟的 国内我们经常用到htt ...

  6. empty函数PHP

    empty译为: adj.空的,空虚的,空洞的;空闲的,无效的,徒劳的;无聊的,愚蠢的;言语或行动空洞的 vt.(使)成为空的, 把…弄空;把…腾出来 vi.成为空的;流空 n.空车;空的东西 是PH ...

  7. PowerDesigner15的安装和破解

    一.PowerDesigner15的安装 运行安装包,出现如下安装界面

  8. android 蓝牙4.0 开发介绍

    最近一直在研究一个蓝牙功能 由于本人是菜鸟  学起来比较忙 一直搞了好久才弄懂 , 网上对蓝牙4.0也就是几个个dome 抄来抄去,全是英文注解 , 对英语不好的朋友来说 真是硬伤 , 一些没必要的描 ...

  9. jdbc mysql - Column count doesn't match value count at row 1.

    该句的意思是,insert操作的SQL语句里列的数目和后面值的数目不一致.比如说, String sql = "insert into t_aqi(city_name, cur_date, ...

  10. Asp.Net MVC安全更新MS14-059导致项目编译失败

    微软最近一次安全更新MS14-059(链接:https://technet.microsoft.com/en-us/library/security/ms14-059)由于直接应用到了machine. ...