模拟题,考验一些细节的东西,但我真的是太笨了,细节方面总是出错。
这一题最关键的是如何用数组表示出这个二维坐标平面,我个人觉得把题目给的图顺时针旋转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相关推荐

  1. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 1 /* 2 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出 ...

  2. POJ 1573 POJ 2632(两道有趣的Robot)实例

    /* ** POJ 2632 Crashing Robots ** Created by Rayn @@ 2014/04/16 ** 坑爹的模拟题,脑壳不清晰的就要被坑惨了 */ #include & ...

  3. HDU 2300 Crashing Robots

    Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...

  4. 【POJ - 2632】Crashing Robots(模拟)

    题干: In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ens ...

  5. 台州学院acm:Crashing Robots

    描述 In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensu ...

  6. hdu与poj题目分类

    POJ 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(po ...

  7. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  8. Winter Camp I (下)

    M题: Stones 代码: #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  9. NKU 专题一 题解

    A - Flip Game 总的情况数只有2^16次方种,显然直接bfs就可以了 1 #include<iostream> 2 #include<queue> 3 #inclu ...

  10. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

最新文章

  1. 第九周项目一-深体验复制(2)
  2. hdu 4888 最大流慢板
  3. linux 下安装node 环境
  4. CentOS登录root账户
  5. SAP CS模块拓展项目实施建议书
  6. java中注解的解析_【Java】中的注解与注解解析器
  7. DjangoORM增删改查
  8. 架构之路(八)从CurrentUser说起
  9. 【OS学习笔记】六 实模式:编写主引导扇区代码
  10. leetcode145. 二叉树的后序遍历 意想不到的骚操作
  11. 表单reset无法重置hidden的解决方案
  12. 【clickhouse】clickhouse : Suspiciously many broken parts to remove.: Cannot attach table default
  13. Centos 5.8 搭建ntp服务器
  14. MATLAB信号处理仿真入门实验
  15. 线阵相机和面阵相机的区别
  16. System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in us
  17. Qt 官方例子 Callout Example
  18. C语言fopen函数的用法,C语言打开文件详解
  19. PCB电路板OSP工艺的优缺点都有哪些?
  20. 分享一些域名在线whois查询

热门文章

  1. 【图文测评】小智的服务器亲测
  2. 几个黑科技、实用网站(转自公众号:趣说软件)
  3. (一百二十三)Android O 了解wifi eap中的anonymous identity
  4. WSUS 3.0 的部署
  5. 不停机与停机更新_Kubernetes的零停机滚动更新
  6. 如何判断时间复杂度和空间复杂度
  7. DANDELION 病毒
  8. 白领失眠危害大 如何拯救上班族?
  9. 在oled屏幕上显示汉字
  10. (转)安装完Fedora 18后需要做的事情