题目链接:

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

题目描述:

  有一个B*A的厂库,分布了n个机器人,机器人编号1~n。我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控机器人,没有两个机器人可以同时执行命令。如果机器人走到厂库边界,他将碰到墙,如果两个机器人走到同一位置,则表示他们两个相撞。问m个命令内最先发生的碰撞,如果没有碰撞输出“OK”。

解题思路:

  由图可知,本题的矩阵与平时的不太一样,所以我们在对厂库进行操作的时候,可以先把厂库顺时针旋转90°,当然,方向也要跟着旋转90°。左右方向是不会跟着变的。然后老老实实的按照命令去模拟,就大功告成啦。

代码:

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std; #define maxn 105 struct node
{
int x, y, s;
} stu[maxn];//每个机器人的位置(x,y),和方向s int dir[][] = {-,, ,, ,, ,-};//翻转后的四个方向:W,N,E,S
int map[maxn][maxn]; int main()
{
int t, A, B, n, m, i, j, flag, x, y, num1, num2;
char ch[]; scanf ("%d", &t);
while (t --)
{
flag = ;//是否发生碰撞
scanf ("%d %d", &A, &B);
scanf ("%d %d", &n, &m);
memset (map, , sizeof(map));
for (i=; i<=n; i++)
{
scanf ("%d %d %s", &stu[i].x, &stu[i].y, ch);
if (ch[] == 'W')
stu[i].s = ;
else if (ch[] == 'N')
stu[i].s = ;
else if (ch[] == 'E')
stu[i].s = ;
else
stu[i].s = ;
map[stu[i].x][stu[i].y] = i;
} while (m --)
{
scanf ("%d%s%d", &x, ch, &y);
if (flag)
continue;
if (ch[] == 'L')//对机器人进行转弯
{
stu[x].s -= y % ;//这里有可能是负数,会导致下面运行re,必须要处理
stu[x].s = (stu[x].s + ) % ;
}
else if (ch[] == 'R')
}
stu[x].s += y;
stu[x].s = (stu[x].s + ) % ;
}
else
{
map[stu[x].x][stu[x].y] = ;
while (y --)//一定要对沿途经过的地方进行判断,是否会有碰撞发生
{
stu[x].x = stu[x].x + dir[stu[x].s][];
stu[x].y = stu[x].y + dir[stu[x].s][];
if (stu[x].x<= || stu[x].x>A || stu[x].y<= || stu[x].y>B)//是否碰撞到墙
{
num1 = x;
flag = ;
break;
}
else if (map[stu[x].x][stu[x].y])//是否碰撞到别的机器人
{
num1 = x;
num2 = map[stu[x].x][stu[x].y];
flag = ;
break;
}
}
map[stu[x].x][stu[x].y] = x;
}
}
if (! flag)
printf ("OK\n");
else if (flag == )
printf ("Robot %d crashes into the wall\n", num1);
else
printf ("Robot %d crashes into robot %d\n", num1, num2);
}
return ;
}

  

poj 2632 Crashing Robots 模拟的更多相关文章

  1. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  2. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  3. 模拟 POJ 2632 Crashing Robots

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

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

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6599   Accepted: 2854 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(较为繁琐的模拟)

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

  8. poj 2632 Crashing Robots_模拟

    做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...

  9. Poj OpenJudge 百练 2632 Crashing Robots

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

随机推荐

  1. jdk8 stream可以与list,map等数据结构互相转换

    前面我们使用过collect(toList()),在流中生成列表.实际开发过程中,List又是我们经常用到的数据结构,但是有时候我们也希望Stream能够转换生成其他的值,比如Map或者set,甚至希 ...

  2. [PythonCode]扫描局域网的alive ip地址

    内网的主机都是自己主动分配ip地址,有时候须要查看下有那些ip在使用,就写了个简单的脚本. linux和windows下都能够用,用多线程来ping1-255全部的地址,效率不高.2分钟左右. 先凑合 ...

  3. 一例Ext4文件系统fsck后损坏的修复过程

    1.故障发生背景 Ext4文件系统没有umount下来,之后做了fsck操作检查一致性,结果导致Ext4文件mount不上(有时也会表现为导致目录变成了文件). 报错提示信息:mount: wrong ...

  4. C#如何引用定义好的dll文件

    1 添加引用,找到dll文件   2 引用类的名称空间,生成类的实例,调用类的方法,测试OK.

  5. Android Studio一些简单设置

          简单设置   1.默认主题设置 默认的 Android Studio 为灰色界面,能够选择使用炫酷的黑色界面. Settings --> Appearance --> Them ...

  6. WEKA简单介绍与资源汇总

    简单介绍 Weka是一个开源的数据挖掘软件,里面集成了很多经典的机器学习算法,在高校和科研机构中受到了广泛的应用. 具体的简单介绍和简单的使用请參考文档:<使用Weka进行数据挖掘>. 学 ...

  7. How to Use SFTP ?

    Usage Build a SFTP session with your linux like server, e.g, by the tool "Xshell" or any y ...

  8. 常见网络摄像机默认使用的端口,RTSP地址

    品牌 默认IP地址 WEB RTSP HTTPS 数据 ONVIF   海康威视 192.168.1.64/DHCP用户名admin 密码自己设 80 554 443 8000 80   大华 192 ...

  9. Unable to find a team with the given Team ID或者Failed to code sign的问题解决

    Unable to find a team with the given Team ID或者Failed to code sign的问题解决 1:问题描述(注:这种情况一般是下载并打开别人项目时) F ...

  10. 清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了

    使用360清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了,但在相应的workspace能够找到项目,这个问题已经是第三次遇到了(预计是被360清理掉Eclipse的一些部署或配置文件所导 ...