题目地址: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. [Effective JavaScript 笔记]第48条:避免在枚举期间修改对象

    注册列表示例 一个社交网络有一组成员,每个成员有一个存储其朋友信息的注册列表. function Member(name){ this.name=name; this.friends=[]; } va ...

  2. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable

    原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  3. 转:PCL+VS2010环境配置

    1.下载 http://www.pointclouds.org/downloads/windows.html出下载PCL完全安装包1.6.0 all-in-one-installer,我的电脑是32位 ...

  4. Coursera台大机器学习技法课程笔记04-Soft-Margin Support Vector Machine

    之前的SVM非常的hard,要求每个点都要被正确的划分,这就有可能overfit,为此引入了Soft SVM,即允许存在被错分的点,将犯的错放在目 标函数中进行优化,非常类似于正则化. 将Soft S ...

  5. Apache VirtualHost配置

    转载:http://www.cnblogs.com/wpjsolo/archive/2012/01/19/2327457.html 以lampp环境为例子,其他环境只是配置文件的路径不同. 先要在   ...

  6. Linux 查看网络连接状态

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

  7. Linux tcp_wrappers 详解

    tcp_wrappers是linux中一个安全机制[TCP_wrappers防火墙],一定程度上限制某种服务的访问权限,达到了保护系统的目的一. 要想用好tcp_wrappers,首先检查某种服务是否 ...

  8. postgresql 锁的定位

    今天碰到了一个问题,锁定穷根追底把postgresql的锁研究了一番. 数据库查看锁 可以通过表 pg_locks来查看有哪些锁.sql如下: select a.locktype,a.database ...

  9. bat批量去除文件首行和合并到文件

    bat批量去除文件首行 set n=1 :starline for %%j in (*.txt) do ( :3 if exist D:\work\test\new_%n%.txt (set /a n ...

  10. Java入门学习知识点汇总

    Java入门重要知识点在这里总结一下,以方便日后复习,这部分内容主要有:变量和常量,常用的运算符,流程控制语句,数组,方法这些内容 一.变量和常量 1.Java关键字 先贴张图: 所有关键字区分大小写 ...