poj 2632 Crashing Robots
模拟题,考验一些细节的东西,但我真的是太笨了,细节方面总是出错。
这一题最关键的是如何用数组表示出这个二维坐标平面,我个人觉得把题目给的图顺时针旋转90度的话,就比较方便。
题源
以下是代码(虽然是从网上看的):
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
const int MAX = 1e3;
struct node
{int x, y;int sign;
};int run[4][2] = {{0,1},{-1,0},{0,-1},{1,0}
};
map<char, int> m;
node pos[MAX];
int maze[MAX][MAX] = { {0} };
int A, B, N, M;
int main()
{m['N'] = 0, m['W'] = 1, m['S'] = 2, m['E'] = 3;int t; cin >> t;while (t--){memset(maze, 0, sizeof(maze));cin >> A >> B >> N >> M; int a, b; char ch; //cout << A << B << N << M;for (int i = 1; i <= N; i++){//cout << i << endl;cin >> pos[i].x >> pos[i].y >> ch;maze[pos[i].x][pos[i].y] = i;pos[i].sign = m[ch];}bool f = false;while (M--){cin >> a >> ch >> b; //cout << a << ch << b << endl;while (b--) {if (f) break;if (ch == 'L') { pos[a].sign = (pos[a].sign + 1) % 4; }else if (ch == 'R') { pos[a].sign = (pos[a].sign + 3) % 4; }else {//cout << a << endl;maze[pos[a].x][pos[a].y] = 0;int x = pos[a].x+= run[pos[a].sign][0], y = pos[a].y+= run[pos[a].sign][1]; //cout << "first " << x << " " << y << endl;//x , y ;//cout << "second " << x << " " << y << " " << B << " " << A << endl;if (x < 1 || y < 1 || x > A || y > B) { f = true;printf("Robot %d crashes into the wall\n", a); break;}else{if (maze[x][y] && maze[x][y] != a) {f = true, printf("Robot %d crashes into robot %d\n", a, maze[x][y]); break;}else maze[x][y] = a;//{ swap(maze[pos[a].x][pos[a].y], maze[x][y]), pos[a].x = x, pos[a].y = y; }}}}}if (!f)cout << "OK" << endl;}return 0;
}
poj 2632 Crashing Robots相关推荐
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 1 /* 2 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出 ...
- POJ 1573 POJ 2632(两道有趣的Robot)实例
/* ** POJ 2632 Crashing Robots ** Created by Rayn @@ 2014/04/16 ** 坑爹的模拟题,脑壳不清晰的就要被坑惨了 */ #include & ...
- HDU 2300 Crashing Robots
Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...
- 【POJ - 2632】Crashing Robots(模拟)
题干: In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ens ...
- 台州学院acm:Crashing Robots
描述 In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensu ...
- hdu与poj题目分类
POJ 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(po ...
- HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Winter Camp I (下)
M题: Stones 代码: #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- NKU 专题一 题解
A - Flip Game 总的情况数只有2^16次方种,显然直接bfs就可以了 1 #include<iostream> 2 #include<queue> 3 #inclu ...
- 杭电oj题目题型分类(转)
1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...
最新文章
- 第九周项目一-深体验复制(2)
- hdu 4888 最大流慢板
- linux 下安装node 环境
- CentOS登录root账户
- SAP CS模块拓展项目实施建议书
- java中注解的解析_【Java】中的注解与注解解析器
- DjangoORM增删改查
- 架构之路(八)从CurrentUser说起
- 【OS学习笔记】六 实模式:编写主引导扇区代码
- leetcode145. 二叉树的后序遍历 意想不到的骚操作
- 表单reset无法重置hidden的解决方案
- 【clickhouse】clickhouse : Suspiciously many broken parts to remove.: Cannot attach table default
- Centos 5.8 搭建ntp服务器
- MATLAB信号处理仿真入门实验
- 线阵相机和面阵相机的区别
- System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in us
- Qt 官方例子 Callout Example
- C语言fopen函数的用法,C语言打开文件详解
- PCB电路板OSP工艺的优缺点都有哪些?
- 分享一些域名在线whois查询