Crashing Robots
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8424   Accepted: 3648

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

题意是给定一个坐标地图,给了很多个机器人的坐标和方向,有三种对机器人的操作方式,F是前进,L是向左转,R向右转。看哪一个机器人先撞墙或是撞到其他机器人。

自己需要注意两点:

1.不一定非得到操作机器人的时候才有冲突,可能在最开始的机器人拜访过程中机器人站的位置就已经重复,即冲突了。

2.R向右转,自己定义成为-1,原来自己以为负数除以数的余数会是正数,结果自己too naive了,要考虑将其变为正数。

这个题自己就注意这两点就够了,因为本身就是一个模拟的过程,跟算法也没什么关系。。。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; struct R
{
int x;
int y;
int dir;
}Robot[110]; enum{ E,N,W,S };
enum{ L=1,R=-1};
int map_f[200][200];
int move_x[5]={1,0,-1,0};
int move_y[5]={0,1,0,-1};
int Test,X,Y,Robot_n,Q,i,flag;
string temp; void solve()
{
int cal_n,cishu,k;
string manu;
cin>>cal_n>>manu>>cishu; if(flag==0)
return; if(manu=="F")
{
map_f[Robot[cal_n].x][Robot[cal_n].y]=0; for(k=1;k<=cishu;k++)
{
Robot[cal_n].x = Robot[cal_n].x + move_x[Robot[cal_n].dir];
Robot[cal_n].y = Robot[cal_n].y + move_y[Robot[cal_n].dir]; if(Robot[cal_n].x <=0 || Robot[cal_n].y <=0 || Robot[cal_n].x >X || Robot[cal_n].y >Y)
{
flag=0;
cout<<"Robot "<<cal_n<<" crashes into the wall"<<endl;
break;
}
else if(map_f[Robot[cal_n].x][Robot[cal_n].y])
{
flag=0;
cout<<"Robot "<<cal_n<<" crashes into robot "<<map_f[Robot[cal_n].x][Robot[cal_n].y]<<endl;
break;
}
}
map_f[Robot[cal_n].x][Robot[cal_n].y]=cal_n;
}
else if(manu=="L")
{
Robot[cal_n].dir = (Robot[cal_n].dir + L*cishu)%4;
}
else if(manu=="R")
{
Robot[cal_n].dir = (Robot[cal_n].dir + (R*cishu)%4 + 4)%4;
}
} int main()
{
cin>>Test; while(Test--)
{
flag=1;
memset(map_f,0,sizeof(map_f)); cin>>X>>Y;
cin>>Robot_n>>Q; for(i=1;i<=Robot_n;i++)
{
cin>>Robot[i].x>>Robot[i].y;
if(map_f[Robot[i].x][Robot[i].y])
{
flag=0;
cout<<"Robot "<<i<<" crashes into robot "<<map_f[Robot[i].x][Robot[i].y]<<endl;
}
else
{
map_f[Robot[i].x][Robot[i].y]=i;
} cin>>temp;
if(temp=="E")
Robot[i].dir=E;
else if(temp=="N")
Robot[i].dir=N;
else if(temp=="W")
Robot[i].dir=W;
else if(temp=="S")
Robot[i].dir=S;
}
for(i=1;i<=Q;i++)
{
solve();
}
if(flag)
cout<<"OK"<<endl;
}
//system("pause");
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 2632:Crashing Robots的更多相关文章

  1. 模拟 POJ 2632 Crashing Robots

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

  2. Poj OpenJudge 百练 2632 Crashing Robots

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

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

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

  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(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  6. poj 2632 Crashing Robots

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

  7. POJ:2632-Crashing Robots

    Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Description In a modernized warehouse, robot ...

  8. 模拟 --- Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7394   Accepted: 3242 D ...

  9. poj2632 Crashing Robots

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

随机推荐

  1. for 循环遍历数据动态渲染html

    本案例通过ajax动态获取数据,然后遍历出数据渲染html小心踩坑:因为有时候不注意,渲染页面的时候只能输出最后一个数据所以正确写法为下:如果AJAX数据请求成功的情况下: html <div ...

  2. 通过CrawlSpider对招聘网站进行整站爬取(拉勾网实战)

    爬虫首先要明确自己要爬取的网站以及内容 进入拉勾网的网站然后看看想要爬取什么内容职位,薪资,城市,经验要求学历要求,全职或者兼职职位诱惑,职位描述提取公司的名称 以及 在拉勾网的url等等 然后在na ...

  3. C++服务器与java进行socket通信案例

    分类: [java]2012-10-08 12:03 14539人阅读 评论(46) 收藏 举报 注:本代码版权所有!!!转载时请声明源地址:http://blog.csdn.net/nuptboyz ...

  4. ROS-4 : ROS节点和主题

    依照<ROS-3 : Catkin工作空间和ROS功能包>,创建catkin工作空间,并在起src下创建功能包ros_demo_pkg,依赖项为roscpp.std_msgs.action ...

  5. sklearn中的多项式回归算法

    sklearn中的多项式回归算法 1.多项式回归法多项式回归的思路和线性回归的思路以及优化算法是一致的,它是在线性回归的基础上在原来的数据集维度特征上增加一些另外的多项式特征,使得原始数据集的维度增加 ...

  6. JuJu团队1月9号工作汇报

    JuJu团队1月9号工作汇报 JuJu   Scrum 团队成员 今日工作 剩余任务 困难 飞飞 将示例程序打包成exe 将crossentrophy和softmax连接起来 无 婷婷 -- 完善ma ...

  7. C语言三种整数类型

    1,int 是 C 语言的基本整数类型,可以满足我们处理一般数据的需求. C 语言还提供了四个可以修饰 int 的关键字:short.long.signed,以及 unsigned. 利用这四个关键字 ...

  8. PAT (Advanced Level) 1132~1135:1132 模拟 1133模拟(易超时!) 1134图 1135红黑树

    1132 Cut Integer(20 分) 题意:将一个含K(K为偶数)个数字的整数Z割分为A和B两部分,若Z能被A*B整除,则输出Yes,否则输出No. 分析:当A*B为0的时候,不能被Z整除,输 ...

  9. POJ 3371:Flesch Reading Ease 模拟

    Flesch Reading Ease Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2071   Accepted: 60 ...

  10. python基础学习(一)

    一,Python介绍 1,python的出生与应用 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打 ...