模拟 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> ...
随机推荐
- Unity 烘焙材质到单一贴图的脚本
原地址:http://www.cocoachina.com/gamedev/gameengine/2011/0406/2756.html 这个脚本由 CocoaChina 版主 “四角钱” 分享,可以 ...
- 彻底理解数字图像处理中的卷积-以Sobel算子为例
彻底理解数字图像处理中的卷积-以Sobel算子为例 作者:FreeBlues 修订记录 2016.08.04 初稿完成 概述 卷积在信号处理领域有极其广泛的应用, 也有严格的物理和数学定义. 本文只讨 ...
- HDU 1708 简单dp问题 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- users
NAME users - print the user names of users currently logged in to the current host SYNOPSIS users [O ...
- chrome控制台支持多行js模式
shift + 回车 是换行 转自: http://zhidao.baidu.com/link?url=MYjGRwvVQYJwnr38VTHPJdzRNtF1COyqpeuAtBYbxFYJcu6p ...
- 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片
aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...
- Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2 ...
- Android studio 添加依赖
以前添加依赖总是到github上下载源码,再添加源码到module的依赖当中,其实在studio中,应该使用maven库. 比如在github上看到了sliding-menu这个项目,就应该到mave ...
- Java for LeetCode 201 Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- 【python】format函数格式化字符串的用法
来源:http://www.jb51.net/article/63672.htm 自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式 ...