题目链接:

https://vjudge.net/problem/POJ-2632

题目大意:

在一个a×b的仓库里有n个机器人,编号为1到n。现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令,每条指令由三部分组成:整数num代表该条指令调用的机器人的编号;字符act表示操作:其中L表示原地向左转90°,R表示原地向右转90°,F表示向前走一步;整数rep表示执行该条指令的次数。已知,当两个机器人坐标相同时他们会相撞,某一个机器人走出仓库也会撞到墙,问你能否安全执行这m条指令,如果能则输出“OK”;否则输出中断原因(哪两个机器人相撞,或是哪个机器人撞到墙了)。

思路:

注意细节,直接模拟

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + ;
const int INF = << ;
int dir[][] = {,,,,-,,,-};
int T, n, m;
struct node
{
int x, y, dir;
};
node a[maxn];
map<char, int>M;
int Map[][];
int main()
{
cin >> T;
int c1, c2;
M['E'] = ;
M['N'] = ;
M['W'] = ;
M['S'] = ;
while(T--)
{
cin >> n >> m;
cin >> c1 >> c2;
char c;
memset(Map, , sizeof(Map));
memset(a, , sizeof(a));
for(int i = ; i <= c1; i++)
{
cin >> a[i].x >> a[i].y >> c;
a[i].dir = M[c];
Map[a[i].x][a[i].y] = i;
}
int flag = , ansid1, ansid2;
for(int i = ; i <= c2; i++)
{
int id, tot;
cin >> id >> c >> tot;
if(flag)continue;
if(c == 'L')
{
a[id].dir += tot;
a[id].dir %= ;
}
else if(c == 'R')
{
a[id].dir -= tot;
a[id].dir = ((a[id].dir % ) + ) % ;
}
else if(c == 'F')
{
Map[a[id].x][a[id].y] = ;
for(int i = ; i <= tot; i++)
{
//cout<<a[id].x<<" "<<a[id].y<<" "<<a[id].dir<<endl;
a[id].x += dir[a[id].dir][];
a[id].y += dir[a[id].dir][]; if(a[id].x <= || a[id].x > n || a[id].y <= || a[id].y > m)
{
flag = ;
ansid1 = id;
break;
}
else if(Map[a[id].x][a[id].y])
{
flag = ;
ansid1 = id;
ansid2 = Map[a[id].x][a[id].y];
}
if(flag)break;
}
Map[a[id].x][a[id].y] = id;
}
}
if(!flag)cout<<"OK"<<endl;
else if(flag == )
cout<<"Robot "<<ansid1<<" crashes into the wall"<<endl;
else cout<<"Robot "<<ansid1<<" crashes into robot "<<ansid2<<endl;
}
return ;
}

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

  1. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

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

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

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

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

  4. 模拟 POJ 2632 Crashing Robots

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

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

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

  6. poj 2632 Crashing Robots(模拟)

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

  7. poj 2632 Crashing Robots

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

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

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

  9. poj 2632 Crashing Robots_模拟

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

  10. Poj OpenJudge 百练 2632 Crashing Robots

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

随机推荐

  1. 斗地主案例(利用集合/增强for等技术)

    斗地主案例(利用集合/增强for等技术) package Task10; import java.util.ArrayList; import java.util.Collections; publi ...

  2. 一篇关于Maven项目的jar包Shell启动脚本

    使用Maven作为项目jar包依赖的管理,常常会遇到命令行启动,笔者也是哥菜鸟,在做微服务,以及服务器端开发的过程中,常常会遇到项目的启动需要使用main方法,笔者潜心的研究了很多博客,发现大多写的都 ...

  3. poj2793 素数和

    题目链接:http://poj.org/problem?id=2739 #include<iostream> using namespace std; int count=0; int p ...

  4. SVN报E155024: Invalid relocation destination

    大家开发过程会遇到一个场景! 我们在使用SVN版本管理工具进行开发的过程中,前一个版本在Branch->201803 分支开发完成之后,后一版本要求在Branch->201804版本开发 ...

  5. poj3358 Period of an Infinite Binary Expansion

    Period of an Infinite Binary Expansion 题目大意:给你一个分数,求这个分数二进制表示下从第几位开始循环,并求出最小循环节长度. 注释:int范围内. 想法:这题说 ...

  6. Linux下的指令:tail

    tail指令常用来查看服务器中的日志信息. 有的时候,需要实时获取日志信息. 比如,我们向服务器发送了一个请求,此时日志有更新,而我们又想实时看到尾部更新的内容. 这时候可以使用指令: tail -f ...

  7. 云计算--网络原理与应用--20171122--STP与HSRP

    简单了解STP 学习HSRP 实验 一.  简单学习STP STP(spanning tree protocol)生成树协议,就是把一个环形的结构改变成一个树形的结构.通过一些算法,在逻辑上阻塞一些端 ...

  8. Semaphore 源码分析

    Semaphore 源码分析 1. 在阅读源码时做了大量的注释,并且做了一些测试分析源码内的执行流程,由于博客篇幅有限,并且代码阅读起来没有 IDE 方便,所以在 github 上提供JDK1.8 的 ...

  9. @Cacheable的实现原理

    如果你用过Spring Cache,你一定对这种配置和代码不陌生: <cache:annotation-driven cache-manager="cacheManager" ...

  10. Alpha冲刺——Day2

    一.合照 二.项目燃尽图 三.项目进展 图形界面基本完成 接口文档框架完成,接下来将会不断细化填充 登录界面向服务器请求数据进行ing 四.明日规划 1.注册登录接口能够完成 2.研究idea实现获得 ...