Crashing Robots
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8388   Accepted: 3631

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

Source

 
 
 
 
 
 
给跪了
做的时候不到一个小时就完事了。结果找bug找了4个小时,就是一个变量写错了,怎么都找不到啊
 
zuile,醉了
#include<iostream>
#include<stdio.h>
#include<string.h>
using  namespace std;
struct node{
    int x;
    int y;
    int z;
}que[200];
int next[4][2]= {0,1,-1,0,0,-1,1,0};
int ans, tx,ty;

int vis[105][105];
int y,x;
void update1(){
    int xx=que[tx].x;
    int yy=que[tx].y;
    int zz=que[tx].z;
    for(int i=1; i<=ty; i++){
        xx+=next[zz][0];
        yy+=next[zz][1];
        if(xx<1||xx>x||yy<1||yy>y){
            printf("Robot %d crashes into the wall\n",tx);
            ans=1;
           return;
        }
         if(vis[xx][yy]!=0){
            printf("Robot %d crashes into robot %d\n",tx,vis[xx][yy]);
            ans=1;
        return;
        }
    }
     vis[xx][yy]=tx;
    vis[que[tx].x][que[tx].y]=0;
    que[tx].x=xx;
    que[tx].y=yy;

}
void update2(){
      que[tx].z=(que[tx].z+ty%4)%4;
}
void update3(){
     que[tx].z=(que[tx].z-ty%4+4)%4;
}
int main(){
    int t,n,m;
    char c;
    scanf("%d",&t);
    while(t--){
        memset(vis,0,sizeof(vis));
        memset(que,0,sizeof(que));
        scanf("%d%d",&x,&y);
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++){
            scanf("%d %d %c",&que[i].x,&que[i].y,&c);
            if(c=='N')  que[i].z=0;
             else  if(c=='W')     que[i].z=1;
              else if(c=='S')    que[i].z=2;
              else  if(c=='E')     que[i].z=3;
              vis[que[i].x][que[i].y]=i;
        }
        ans=0;
        for(int i=1; i<=m; i++){
           scanf("%d %c %d",&tx,&c,&ty);
            if(ans==0){
            if(c=='F')
                update1();
            else  if(c=='L')
                update2();
            else  if(c=='R')
                update3();
            }
        }
        if(ans==0)
            printf("OK\n");

}
    return 0;
}

poj2632 模拟的更多相关文章

  1. POJ-2632 Crashing Robots模拟

    题目链接: https://vjudge.net/problem/POJ-2632 题目大意: 在一个a×b的仓库里有n个机器人,编号为1到n.现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令 ...

  2. POJ2632 Crashing Robots(模拟)

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

  3. poj2632 【模拟】

    In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure ...

  4. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  5. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  6. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  7. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  8. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  9. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

随机推荐

  1. Memcached——非关系型数据库分布式处理

    Memcached登录校验应用: MMCacheWriter.cs类 using Memcached.ClientLibrary; using System; using System.Collect ...

  2. 每天一个linux命令(21):tar命令

    通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...

  3. 软工实践练习一(个人)----将Androidstudio的项目共享到github

    在Androidstudio上使用git插件 将项目共享至github 将 显示共享成功但是出了点问题 项目文件并没有上传至github库中,而是只创建了一个新的库 问题在于我的gitforwindo ...

  4. java多线程-CyclicBarrier

    介绍 一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待,此时 CyclicBa ...

  5. DML语言练习,数据增删改查,复制清空表

    Connected Connected as TEST@ORCL SQL> select * from t_hq_bm; BUMBM BUMMC DIANH ---------- ------- ...

  6. Java-日期转换

    如下: package 时间日期类; import java.text.SimpleDateFormat; import java.util.Date; public class 日期格式转换 { / ...

  7. C++用new和不用new创建类对象区别

    new创建类对象,使用完后需使用delete删除,跟申请内存类似.所以,new有时候又不太适合,比如在频繁调用场合,使用局部new类对象就不是个好选择,使用全局类对象或一个经过初始化的全局类指针似乎更 ...

  8. ISO 基础之 (十二) 文件管理

    一 文件管理 沙盒:让每个APP应用在手机上有一个独立的文件夹,相互之间不能访问. 沙盒目录:NSHomeDirectory() library: 库文件 tmp: 临时文件 1.NSData 也是一 ...

  9. java变量作用域

      1.public:public表明该数据成员.成员函数是对所有用户开放的,所有用户都可以直接进行调用 2.private:private表示私有,私有的意思就是除了class自己之外,任何人都不可 ...

  10. json格式不对引起的报错

    报JSONDecondeError这种类型的错误的时候就要检查下json格式是否是正确的了,这里提供一个http://www.bejson.com/ Traceback (most recent ca ...