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

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 warehouseFinally 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

Source

 #include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;
struct robot
{
int x , y ;
int dir ;
}a[]; struct instruction
{
int num ;
char act ;
int rep ;
}ins[]; int EW , NS ;
int n , m ;
bool flag ;
int map[][]; void crash (int No)
{
int k = ins[No].rep ;
int t = ins[No].num ;
map[a[t].x][a[t].y] = ;
switch (a[t].dir)
{
case :
for (int i = ; i < k && a[t].x && a[t].y ; i++)
if (map[a[t].x][++a[t].y]) {
flag = ;
printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
break ;
}
break ;
case :
for (int i = ; i < k && a[t].x && a[t].y ; i++)
if (map[++a[t].x][a[t].y]) {
flag = ;
printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
break ;
}
break ;
case :
for (int i = ; i < k && a[t].x && a[t].y ; i++)
if (map[a[t].x][--a[t].y]) {
flag = ;
printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
break ;
}
break ;
case :
for (int i = ; i < k && a[t].x && a[t].y; i++)
if (map[--a[t].x][a[t].y]) {
flag = ;
printf ("Robot %d crashes into robot %d\n" , t , map[a[t].x][a[t].y]) ;
break ;
}
break ;
}
map[a[t].x][a[t].y] = t ;
if (a[t].x == || a[t].x >= EW + || a[t].y == || a[t].y >= NS + ) {
printf ("Robot %d crashes into the wall\n" , t) ;
flag = ;
}
}
void solve (int No)
{
int k = ins[No].num ;
switch (ins[No].act)
{
case 'L' : a[k].dir -= ins[No].rep ; a[k].dir %= ; a[k].dir += ; a[k].dir %= ; break ;
case 'R' : a[k].dir += ins[No].rep ; a[k].dir %= ; a[k].dir += ; a[k].dir %= ; break ;
case 'F' : crash (No) ;
}
}
int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int T ;
scanf ("%d" , &T) ;
char temp ;
while (T--) {
memset (map , , sizeof(map) ) ;
scanf ("%d%d" , &EW , &NS) ;
scanf ("%d%d" , &n , &m) ;
for (int i = ; i <= n ; i++) {
cin >> a[i].x >> a[i].y >> temp ;
// cout << temp <<endl ;
map[a[i].x][a[i].y] = i ;
switch (temp)
{
case 'E' : a[i].dir = ; break ;
case 'S' : a[i].dir = ; break ;
case 'W' : a[i].dir = ; break ;
case 'N' : a[i].dir = ; break ;
}
// printf ("a[%d].dir=%d\n" , i , a[i].dir) ;
}
for (int i = ; i < m ; i++)
cin >> ins[i].num >> ins[i].act >> ins[i].rep ; flag = ;
// printf ("a[1].dir=%d\n" , a[1].dir) ;
for (int i = ; i < m ; i++) {
/* for (int i = 1 ; i <= EW ; i++) {
for (int j = 1 ; j <= NS ; j++) {
printf ("%d " , map[i][j]) ;
}
puts("");
}
puts ("") ;*/
solve (i) ;
/* for (int i = 1 ; i <= EW ; i++) {
for (int j = 1 ; j <= NS ; j++) {
printf ("%d " , map[i][j]) ;
}
puts("");
}
printf ("\n\n\n") ; */
if (flag)
break ;
} if (!flag)
puts ("OK") ;
}
return ;
}

规规矩矩得模拟 robot 一步步走就行了

Crashing Robots(imitate)的更多相关文章

  1. POJ2632 Crashing Robots(模拟)

    题目链接. 分析: 虽说是简单的模拟,却调试了很长时间. 调试这么长时间总结来的经验: 1.坐标系要和题目建的一样,要不就会有各种麻烦. 2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a ...

  2. poj 2632 Crashing Robots(模拟)

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

  3. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(数学)

    题意: n 道题,2 个答题者,已知二者的做题情况,你是受贿裁判,可以给每题指定分值(≥1),求甲乙分数(甲>乙)相差最小时最大分值的最小值. 思路: 统计只有甲或乙做出的题目数. 加一取下整判 ...

  4. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

  5. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  6. [AGC004E] Salvage Robots (DP)

    Description 蛤蟆国的领土我们可以抽象为H*W的笼子,在这片蛤土上,有若干个机器人和一个出口,其余都是空地,每次蛤蟆会要求让所有的机器人向某个方向移动一步,当机器人移动到出口时会被蛤蟆活摘出 ...

  7. 【ZOJ1003】Crashing Balloon(DFS)

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

  8. UVALive 7464 Robots (贪心)

    Robots 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/K Description http://7xjob4.com1.z ...

  9. UVALive 7464 Robots(模拟)

    7464Robots Write a program to collect data from robots. We are given two sets of robotsX=fX1;:::;Xmg ...

随机推荐

  1. 教你写一个Android可快速复用的小键盘输入控件

    引子 在Android项目开发中特别是一些稍大型的项目,面对需求文档的时候你经常会发现很多地方用到了同样的组件,但是又略有不同.比如这个: 右边是一个小键盘输入板,左边当焦点不同的时候分别用右边的小键 ...

  2. 图片ping、JSONP和CORS跨域

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<由外边距合并到BFC> 作者主页:myvin 博主QQ:851399101(点击QQ和博主发起临时会话 ...

  3. 记录我学github的路程(二)

    2015-12-09 更新 1,现在,本地有了一个库,你可能会想到GitHub创建一个库,并且关联起来.这样,远程的库既可以当作备份,又可以让其他人通过该仓库来协作. 2,步骤: (1)登录GitHu ...

  4. 用Wireshark抓包分析超过70秒的请求

    超过70秒的请求是通过分析IIS日志发现的: 10.159.63.104是SLB的内网IP. 通过Wireshark抓包分析请求是9:22:21收到的(tcp.stream eq 23080): 09 ...

  5. Shadowsock搭建

    搭建Shadowsocks服务端: 搭建Shadowsocks之前首先必须购买一个VPS.一般VPS提供商会给一个测试地址,购买之前最好先ping一下速度.也可以通过以下网址测试下vps网络速度: h ...

  6. sql server快速删除整个数据库表和存储过程

    情况:在远程数据库删除表执行太慢,表过多,数据库无权删除 结果:保留空数据库 方法:利用sql语句,查询网络文摘解决. 说明: 有些有约束,不能直接delete,需要先删除所有约束,语句: DECLA ...

  7. [poj3274]排排站(Hash)

    题目:http://poj.org/problem?id=3274 题目大意:http://www.wikioi.com/problem/1247/ (此题中文版) 分析: 令sum[i][j]表示a ...

  8. Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合

    题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...

  9. Calender的使用详解

    Calendar和GregorianCalendar简介 Calendar的中文翻译是日历,实际上,在历史上有着许多种计时的方法.所以为了计时的统一,必需指定一个日历的选择.那现在最为普及和通用的日历 ...

  10. zabbix 乱码的问题

    文章转自:http://www.ttlsa.com/zabbix/zabbix-chinese-garbled-ttlsa/ 在使用zabbix的时候发现图片下方的中文都是一个个小方格 这是zabbi ...