题目地址:http://poj.org/problem?id=2632

 /*
题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到;如果走出界了,输出谁出界
如果以上都没发生,则输出OK
模拟题:无算法,按照条件编写几个函数和判断条件
注意:1. 关于绕转,只要模拟人的转圈方向,比如向右转就向右手边转(优化:当超过4次则对4取模)
2. 有先撞墙还是先撞机器人的问题(每一次'F'后都要及时判断是否OK)
3. 撞哪个机器人也有先来后到的顺序('F'后以这个机器人(除自己以外)遍历一边是否OK)
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
struct NODE
{
int x, y;
int dir;
}node[MAXN];
struct OP
{
int name, t;
char move;
}op[MAXN];
bool flag; bool ok(int k, int N, int M, int n)
{
for (int i=; i<=n; ++i)
{
if (node[i].x < || node[i].x > N || node[i].y < || node[i].y > M)
{
printf ("Robot %d crashes into the wall\n", i);
flag = false;
return false;
}
} for (int j=; j<=n; ++j)
{
if (k != j && node[k].x == node[j].x && node[k].y == node[j].y)
{
printf ("Robot %d crashes into robot %d\n", k, j);
flag = false;
return false;
}
} flag = true;
return true;
} void forward(NODE *a, OP b, int N, int M, int n)
{
while (b.t--)
{
if (a->dir == 'N') a->x -= ;
else if (a->dir == 'S') a->x += ;
else if (a->dir == 'W') a->y -= ;
else a->y += ;
if (!ok (b.name, N, M, n)) break;
}
} NODE turn_l(NODE a, OP b)
{
b.t = (b.t >= ) ? (b.t % ) : b.t;
while (b.t--)
{
if (a.dir == 'N') a.dir = 'W';
else if (a.dir == 'S') a.dir = 'E';
else if (a.dir == 'E') a.dir = 'N';
else a.dir = 'S';
} return a;
} NODE turn_r(NODE a, OP b)
{
b.t = (b.t >= ) ? (b.t % ) : b.t;
while (b.t--)
{
if (a.dir == 'N') a.dir = 'E';
else if (a.dir == 'S') a.dir = 'W';
else if (a.dir == 'W') a.dir = 'N';
else a.dir = 'S';
} return a;
} void work(int N, int M, int n, int m)
{
int i;
for (i=; i<=m; ++i)
{
if (op[i].move == 'F')
forward (&node[op[i].name], op[i], N, M, n);
else if (op[i].move == 'L')
node[op[i].name] = turn_l (node[op[i].name], op[i]);
else if (op[i].move == 'R')
node[op[i].name] = turn_r (node[op[i].name], op[i]);
if (flag) continue;
else break;
}
if (i == m + ) puts ("OK");
} int main(void) //POJ 2632 Crashing Robots
{
//freopen ("G.in", "r", stdin); int t;
scanf ("%d", &t);
while (t--)
{
int N, M, n, m;
scanf ("%d%d", &M, &N);
scanf ("%d%d", &n, &m);
for (int i=; i<=n; ++i)
{
scanf ("%d %d %c", &node[i].y, &node[i].x, &node[i].dir);
node[i].x = N + - node[i].x;
}
for (int i=; i<=m; ++i)
{
scanf ("%d %c %d", &op[i].name, &op[i].move, &op[i].t);
} flag = true;
work (N, M, n, m);
} return ;
} /*
Robot 1 crashes into the wall
Robot 1 crashes into robot 2
OK
Robot 1 crashes into robot 2
*/

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

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

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

  2. poj 2632 Crashing Robots(模拟)

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

  3. poj 2632 Crashing Robots

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

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

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

  5. poj 2632 Crashing Robots 模拟

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

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

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

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

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

  8. Poj OpenJudge 百练 2632 Crashing Robots

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

  9. poj 2632 Crashing Robots_模拟

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

随机推荐

  1. cocos进阶教程(2)多分辨率支持策略和原理

    cocos2d-x3.0API常用接口 Director::getInstance()->getOpenGLView()->setDesignResolutionSize() //设计分辨 ...

  2. [Android教程]EditText怎样限制用户的输入?数字/字母/邮箱

    有输入必有验证.为了防止用户随便输入确保提交数据的合法性,程序不得不在文本输入框(EditText)中增加限制或验证. 关于输入类型有数字.字母.邮箱.电话等形式,这些具体得根据业务来.那么Andro ...

  3. notepad正则表达式

    文件名称匹配 文件名称: boost_chrono-vc100-mt-1_49.dll 对应的notepad正则表达式: \w*_\w*-\w*-\w*-\w*-\w*.dll 移除空行 查找目标: ...

  4. Jackson 框架,轻易转换JSON

    Jackson 框架,轻易转换JSON Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在 ...

  5. Linux 查看网络连接状态

    CLOSED:无连接是活动的或正在进行ESTABLISED:已建立连线的状态:SYN_SENT:发出主动连线 (SYN 标志) 的连线封包:SYN_RECV:接收到一个要求连线的主动连线封包:FIN_ ...

  6. SpringMVC配置easyui-datagrid

    SprimgMVC的UserController.java @RequestMapping(value = "listUserForJson") @ResponseBody pub ...

  7. dell idrac8 部署操作系统的方法

    1,打开虚拟控制台 2,“虚拟介质”->“连接虚拟介质”->“映射虚拟介质到CD”->(选择要安装的镜像文件)->“Map device” 3, “next boot”-> ...

  8. 《转》Visual Studio 2010 终极定制安装精简方法

    打开VS2010安装目录下的 Setup 文件夹,找到 baseline.dat 文件和 vs_setup.pdi 文件还有一个 locdata.ini 文件,是对应的. 这些都是文本文件,用记事本就 ...

  9. python提取百万数据到csv文件

    转自:http://www.2cto.com/kf/201311/258112.html 今天有需求,需要把系统所有用户注册的id和邮箱等信息导出来提供给他们,在mysql里面count了下,大概有3 ...

  10. windows下如何对mysql进行整裤备份

    通常情况下备份一个数据库,直接单裤备份即可,更完善一点的会要求做到定时单裤备份.然而很多时候又由于裤实例是在太多,这样会导致备份非常耗时,因而有时候需要对整个数据库应用进行备份.那么在windows下 ...