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

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

【题目来源】

Nordic 2005

http://poj.org/problem?id=2632

【题目大意】

poj 2632
在一个大型仓库里,机器人常常需要来往取货。需要一系列的指令来操作机器人使得每个机器人移动到他的目的地。并且不能撞到其他的机器人。当然,所有的仓库都是矩形的,每个的机器人占据一个半径为1的圆形。
假定有N个机器人,编号为1到N。你将会知道每个机器人的位置和方向,并且所有下达的指令,机器人将会听从这些指令。指令出来后将会被处理。
没有两个机器人将会同时移动,每个机器人移动完后下一个机器人才会移动。
一个机器人撞到墙壁的话,他将会被撞毁;如果两个机器人相撞的话,两个机器人都将会被撞毁。

输入:
第一行是一个整数K,表示测试情况有K个。
每个测试情况的第一行是两个整数,1<=A,B<=100,表示这个仓库的大小。A表示横向的长度,B表示纵向的长度。
第二行有两个数,1<=N,M<=100,分别表示机器人的数量和指令数目。
接下来有N行,每行有两个数字和一个字母(N,S,E,W),表示每一个机器人的坐标和方向。没有相同的两个机器人在相同的位置上。
最后是M行,代表一连串的指令。
每个指令的格式如下:
<哪个机器人><要执行的动作><重复的次数>

其中动作包括:
L:向左转90度
R:向右转90度
F:向前走

每次重复的次数大于等于1小于等于10。

输出:
每个test case输出1行。
输出包括:
如果机器人i撞到了墙壁,那么输出:Robot i crashes into the wall
如果机器人i撞到了机器人j,那么输出:Robot i crashes into robot j
如果没有机器人相撞,那么输出:OK

只需要报告第一次撞击。

【题目分析】

比较简单的长模拟,就是代码长,估计是被我写残了,写了250多行。做的时候要注意细节,比如说这题的地图的y轴和数组是反的,做的时候要反过来,还有横纵坐标也是反的。注意了这些细节就可以ac了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define MAX 150
using namespace std;
struct Node
{
bool have;
int dir;
int number;
}; Node Map[MAX][MAX];
int A,B; struct Order
{
int num;
char op;
int time;
};
Order order[MAX]; void make_Map(int n,int m)
{
int i,j;
for(i=;i<=n+;i++)
{
for(j=;j<=m+;j++)
{
Map[i][j].have=false;
Map[i][j].dir=;
Map[i][j].number=;
}
}
//将地图围起来,这里可以使用dir这个值来标记围墙
for(i=;i<=n+;i++)
Map[i][].dir=Map[i][m+].dir=-;
for(i=;i<=m+;i++)
Map[][i].dir=Map[n+][i].dir=-;
// for(i=0;i<=n+1;i++)
// {
// for(j=0;j<=m+1;j++)
// {
// printf("%d ",Map[i][j].dir);
// }
// puts("");
// }
} bool go(int num,char op,int time)
{
// printf("num=%d op=%c time=%d\n",num,op,time);
int i,j;
int x1,y1;
int number1,dir1;
// for(i=1;i<=B;i++)
// {
// for(j=1;j<=A;j++)
// {
// printf("%d ",Map[i][j].number);
// }
// puts("");
// }
for(i=;i<=B;i++)
{
for(j=;j<=A;j++)
{
if(Map[i][j].number==num)
{
x1=i;
y1=j;
break;
}
}
}
// printf("x1=%d y1=%d\n",x1,y1);
if(op=='L') //右转90度
{
for(i=;i<=time;i++)
{
Map[x1][y1].dir=(Map[x1][y1].dir+)%;
}
}
else if(op=='R') //左转90度
{
for(i=;i<time;i++)
{
Map[x1][y1].dir=(Map[x1][y1].dir-);
if(Map[x1][y1].dir==)
Map[x1][y1].dir=;
}
}
else //前进
{
// printf("x1=%d y1=%d\n",x1,y1);
// printf("Map[%d][%d].dir=%d\n",x1,y1,Map[x1][y1].dir);
switch(Map[x1][y1].dir)
{
case : //往上走
number1=Map[x1][y1].number;
dir1=Map[x1][y1].dir;
Map[x1][y1].number=;
Map[x1][y1].have=!Map[x1][y1].have;
// printf("This is case 1\n");
for(i=;i<time;i++)
{
x1--;
if(Map[x1][y1].have) //遇到了其他机器人
{
printf("Robot %d crashes into robot %d\n",number1,Map[x1][y1].number);
return true;
}
if(Map[x1][y1].dir==-)//撞到了墙
{
printf("Robot %d crashes into the wall\n",number1);
return true;
}
}
Map[x1][y1].have=true;
Map[x1][y1].dir=dir1;
Map[x1][y1].number=number1;
break;
case : //往右走
number1=Map[x1][y1].number;
dir1=Map[x1][y1].dir;
Map[x1][y1].number=;
Map[x1][y1].have=!Map[x1][y1].have;
// printf("This is case 2\n");
for(i=;i<time;i++)
{
y1++;
if(Map[x1][y1].have) //遇到了其他机器人
{
printf("Robot %d crashes into robot %d\n",number1,Map[x1][y1].number);
return true;
}
if(Map[x1][y1].dir==-)//撞到了墙
{
printf("Robot %d crashes into the wall\n",number1);
return true;
}
}
Map[x1][y1].have=true;
Map[x1][y1].dir=dir1;
Map[x1][y1].number=number1;
break;
case ://往下走
number1=Map[x1][y1].number;
dir1=Map[x1][y1].dir;
Map[x1][y1].number=;
Map[x1][y1].have=!Map[x1][y1].have;
// printf("This is case 3\n");
for(i=;i<time;i++)
{
x1++;
if(Map[x1][y1].have) //遇到了其他机器人
{
printf("Robot %d crashes into robot %d\n",number1,Map[x1][y1].number);
return true;
}
if(Map[x1][y1].dir==-)//撞到了墙
{
printf("Robot %d crashes into the wall\n",number1);
return true;
}
}
Map[x1][y1].have=true;
Map[x1][y1].dir=dir1;
Map[x1][y1].number=number1;
break;
case ://往左走
number1=Map[x1][y1].number;
dir1=Map[x1][y1].dir;
Map[x1][y1].number=;
Map[x1][y1].have=!Map[x1][y1].have;
// printf("This is case 4\n");
for(i=;i<time;i++)
{
y1--;
if(Map[x1][y1].have) //遇到了其他机器人
{
printf("Robot %d crashes into robot %d\n",number1,Map[x1][y1].number);
return true;
}
if(Map[x1][y1].dir==-)//撞到了墙
{
printf("Robot %d crashes into the wall\n",number1);
return true;
}
}
Map[x1][y1].have=true;
Map[x1][y1].dir=dir1;
Map[x1][y1].number=number1;
break;
}
}
return false;
} int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int T;
cin>>T;
while(T--)
{
cin>>A>>B;
make_Map(B,A);//注意,题目给的方向要反过来
int N,M;
cin>>N>>M;
int i,j,k;
int x1,y1;
char c;
for(i=;i<N;i++)
{
scanf("%d %d %c",&y1,&x1,&c);
Map[x1][y1].have=true;
if(c=='S')
Map[x1][y1].dir=;
else if(c=='E')
Map[x1][y1].dir=;
else if(c=='N')
Map[x1][y1].dir=;
else
Map[x1][y1].dir=;
Map[x1][y1].number=i+;
// cout<<Map[x1][y1].number<<endl;
// cout<<"x1="<<x1<<" "<<"y1="<<y1<<" "<<"c="<<c<<endl;
}
int number1;
char op;
int time;
for(i=;i<M;i++)
{
scanf("%d %c %d",&order[i].num,&order[i].op,&order[i].time);
// printf("%d %c %d\n",order[i].num,order[i].op,order[i].time);
}
bool flag=false;
for(i=;i<M;i++)
{
// printf("num=%d op=%c time%d\n",order[i].num,order[i].op,order[i].time);
if(go(order[i].num,order[i].op,order[i].time))
{
flag=true;
break;
}
}
if(!flag)
printf("OK\n");
}
return ;
}

模拟 --- Crashing Robots的更多相关文章

  1. 模拟 POJ 2632 Crashing Robots

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

  2. Crashing Robots(水题,模拟)

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

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

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

  4. poj2632 Crashing Robots

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

  5. Crashing Robots(imitate)

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

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

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

  7. poj 2632 Crashing Robots

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

  8. Poj OpenJudge 百练 2632 Crashing Robots

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

  9. POJ2632——Crashing Robots

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

随机推荐

  1. Spring事务源码解析(二)获取增强

    在上一篇文章@EnableTransactionManagement注解解析中,我们搭建了源码阅读的环境,以及解析了开启Spring事务功能的注解@EnableTransactionManagemen ...

  2. CSS 总结 [目录]

    一.CSS 基础 1.CSS 初识 2.CSS 用法和特性 二.CSS 选择器 1.基本选择器 2.组合选择器 3.属性选择器 4.伪类选择器 5.伪元素选择器 三.CSS 字体样式 四.CSS 文本 ...

  3. windows10删除多出的oem分区

    某次windows升级后,磁盘管理里新出现一个500多M的OEM分区 其实系统里本来就有一个OEM分区是第一个分区,大小499M,可能因为这个分区太小,系统就又新建一个 因为在windows10分区后 ...

  4. idea 2019 集成activiti, idea activiti 新建bpmn文件, 解决idea activiti中文乱码

    idea 在线安装activiti插件 1. File-->Settings 2. 点击Plugins, 右侧界面点击Marketplace后在搜索框搜索 actiBPM 注: 网络原因没有加载 ...

  5. canal中间件

    简介: 基于数据库增量(模拟MySQL slave的交互协议)日志解析,提供增量数据订阅和消费(客户端与canal建立关系) 安装版本:1.1.0 git 环境需求: jdk1.7以上 mysql开启 ...

  6. 对NetBackup 问题进行故障排除的步骤

    错误消息通常是指出哪里出现故障的手段.如果在界面上没有看到错误消息,但仍怀疑有问题,请检查报告和日志. NetBackup提供了各种报告和日志记录工具, 这些工具可提供错误消息,直接为您指出解决方案. ...

  7. python 和 R 语言中的等差数列

    等差数列的通项公式:an = a0 + n*d. 数学上 n 是可以取遍整个整个正整数集的,在现实中,n  是有范围的. 1.R 语言用 seq()  函数产生等差数列: 2.python 中 ran ...

  8. Ubuntu 出现access denied by server while mounting

    3516cv500板端nfst调试时如此配置 虚拟机: #vi /etc/exports  添加 /home/"待分享文件路径"   *(rw,sync,no_root_squas ...

  9. Python并发编程之进程通信

    ''' 进程间的通信 ''' """ multiprocessing模块支持进程间通信的两种主要形式:管道和队列 都是基于消息传递实现的, ""&qu ...

  10. Scrapy笔记(1)- 入门篇

    Scrapy笔记01- 入门篇 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架.可以应用在包括数据挖掘, 信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取(更确切来说, ...