模拟 POJ 2632 Crashing Robots
题目地址: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的更多相关文章
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- POJ 2632 Crashing Robots(较为繁琐的模拟)
题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- poj 2632 Crashing Robots_模拟
做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...
随机推荐
- 机器学习公开课笔记(8):k-means聚类和PCA降维
K-Means算法 非监督式学习对一组无标签的数据试图发现其内在的结构,主要用途包括: 市场划分(Market Segmentation) 社交网络分析(Social Network Analysis ...
- Valid Pattern Lock(dfs + 暴力)
Valid Pattern Lock Time Limit: 2 Seconds Memory Limit: 65536 KB Pattern lock security is genera ...
- cf.VK CUP 2015.B.Mean Requests
Mean Requests time limit per test 4 seconds memory limit per test 256 megabytes input standard input ...
- poj.1094.Sorting It All Out(topo)
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28762 Accepted: 99 ...
- XSS代码触发条件,插入XSS代码的常用方法
1.脚本插入 (1)插入javascript和vbscript正常字符. 例1:<img src=”javascript:alert(/xss/)”> 例2:<table backg ...
- linux 客户端 Socket 非阻塞connect编程
开发测试环境:虚拟机CentOS,windows网络调试助手 非阻塞模式有3种用途 1.三次握手同时做其他的处理.connect要花一个往返时间完成,从几毫秒的局域网到几百 ...
- mysql启动报错(mac)
$mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) ...
- hiho一下 第九十八周 搜索一·24点
题目1 : 搜索一·24点 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 周末,小Hi和小Ho都在家待着. 在收拾完房间时,小Ho偶然发现了一副扑克,于是两人考虑用这副 ...
- 在Windows Server 2012 中安装 .NET 3.5 Framework
问题 如今,仍然有许多程序和应用需要依靠.NET 3.5 framework 来运行.在Windows Server 2012中,微软提供了.NET 3.5 和.NET 4.5的安装选项以为你的应用程 ...
- HDOJ 1856
#include<cstdio> #include<cstdlib> typedef struct ufse *ufset; struct ufse { ]; ]; }UFS; ...