【POJ - 2632】Crashing Robots(模拟)

题干:

In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occupy a circular floor space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.

Input

The first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively. 
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position. 

 
Figure 1: The starting positions of the robots in the sample warehouse


Finally there are M lines, giving the instructions in sequential order. 
An instruction has the following format: 
< robot #> < action> < repeat> 
Where is one of 

  • L: turn left 90 degrees, 
  • R: turn right 90 degrees, or 
  • F: move forward one meter,


and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.

Output

Output one line for each test case: 

  • Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.) 
  • Robot i crashes into robot j, if robots i and j crash, and i is the moving robot. 
  • OK, if no crashing occurs.


Only the first crash is to be reported.

Sample Input

4
5 4
2 2
1 1 E
5 4 W
1 F 7
2 F 7
5 4
2 4
1 1 E
5 4 W
1 F 3
2 F 1
1 L 1
1 F 3
5 4
2 2
1 1 E
5 4 W
1 L 96
1 F 2
5 4
2 3
1 1 E
5 4 W
1 F 4
1 L 1
1 F 20

Sample Output

Robot 1 crashes into the wall
Robot 1 crashes into robot 2
OK
Robot 1 crashes into robot 2

题目大意:

机器人移动。给你一些机器人的初始位置和朝向和一些移动指令。要你判断在指令执行的过程中是否有机器人撞墙或者两个机器人相撞的情况。

解题报告:

   直接模拟就行了。当时因为在,左右转的那里,to = r[num].dir;写成了to=go(op[0]),所以WA了。还是要注意细节啊!!

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
int maze[105][105];
int a,b;
int n,m; 
int nx[4] = {1,0,-1,0};//右,下,左,上
int ny[4] = {0,-1,0,1};//右,下,左,上
struct Node {int x,y;int dir;
} r[555];
int go(char x) {if(x == 'E') return 0;if(x == 'S') return 1;if(x == 'W') return 2;if(x == 'N') return 3;
}
int main()
{int t;int gg = 0;char op[5];cin>>t;while(t--) {gg = 0;int ans1,ans2;memset(maze,0,sizeof maze);scanf("%d%d",&a,&b);scanf("%d%d",&n,&m);//robot个数和指令数for(int i = 1; i<=n; i++) {scanf("%d%d%s",&r[i].x,&r[i].y,op);r[i].dir = go(op[0]);maze[r[i].x][r[i].y] = i;}for(int i = 1; i<=m; i++) {int num,rep;scanf("%d%s%d",&num,op,&rep);if(gg != 0) continue;int to;if(op[0] == 'F') {to = r[num].dir;for(int j = 1; j<=rep; j++) {int tx = r[num].x + nx[to];int ty = r[num].y + ny[to];if(tx < 1 || tx > a || ty < 1 || ty > b) {gg = 2;ans1 = num;break;}if(maze[tx][ty] != 0) {gg=1;//撞人了;ans1 = num;ans2 = maze[tx][ty];break;}maze[tx][ty] = num;maze[r[num].x][r[num].y]=0;r[num].x=tx;r[num].y=ty;}				}else {				to = r[num].dir;while(rep>4) rep-=4;for(int j = 1; j<=rep; j++) {if(op[0] == 'L') {to = (to+4-1)%4;}else to = (to+1)%4;}r[num].dir = to;}}if(gg == 1) {printf("Robot %d crashes into robot %d\n",ans1,ans2);}else if(gg == 2) {printf("Robot %d crashes into the wall\n",ans1);}else puts("OK");}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440574.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一台linux上运行多个mysql_linux下同时运行多个mysql

来自网络&#xff0c;感谢开源&#xff0c;感谢分享通过rpm安装mysql&#xff0c;测试版本5.1.481、在linux下通过:#useradd multi -g mysql -s /sbin/nologin添加一个multi用户&#xff0c;并加入到mysql组#passwd multi给multi用户添加密码&#xff0c;这里设置的密码为multi…

【SPOJ - QTREE2】Query on a tree II(LCA,倍增)

题干&#xff1a; You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. Each edge has an integer value assigned to it, representing its length. We will ask you to perfrom some instructions of the foll…

pandownload用户未登录_Pandownload再度复活,下载速度飙升到10MB/s以上

PanDownload再度复活版&#xff0c;此版镜像服务器由新城旧梦维护卢本伟修改版&#xff0c;基本都是维持在10M/S的下载速度&#xff0c;如果你的宽带够大&#xff0c;下载速度会更快&#xff0c;无需安装即可免费使用&#xff0c;但是需要登陆才能下载。(Pandownload卢本伟修改…

【蓝桥杯 - 试题】立方尾不变(tricks,快速取出一个数字的后n位)

题干&#xff1a; 有些数字的立方的末尾正好是该数字本身。 比如&#xff1a;1,4,5,6,9,24,25,.... 请你计算一下&#xff0c;在10000以内的数字中&#xff08;指该数字&#xff0c;并非它立方后的数值&#xff09;&#xff0c;符合这个特征的正整数一共有多少个。 请提交该…

momentjs转换格式_Moment.js+Vue过滤器的使用,各种时间格式转换为YYYY-MM-DD HH:mm:ss格式...

前言这篇文章将Moment.js与vue过滤器连用。如果不会过滤器的朋友&#xff0c;可以先看这篇文章vue过滤器一、Moment.js是什么&#xff1f;Moment.js是JavaScript 日期处理类库。使用场景&#xff1a;vue项目中经常需要将时间戳转换为各种时间格式再显示。二、使用步骤1.安装这里…

【HDU - 1943】Ball bearings(几何问题)

题干&#xff1a; The Swedish company SKF makes ball bearings. As explained by Britannica Online, a ball bearing is “one of the two types of rolling, or anti friction, bearings (the other is the roller bearing). Its function is to connect two machine mem…

mysql显示修改密码_MySQL修改密码

第一种方式&#xff1a;最简单的方法就是借助第三方工具Navicat for MySQL来修改&#xff0c;方法如下&#xff1a;1、登录mysql到指定库&#xff0c;如&#xff1a;登录到test库。2、然后点击上方“用户”按钮。3、选择要更改的用户名&#xff0c;然后点击上方的“编辑用户”按…

【POJ - 2486】Apple Tree (树形背包,dp)

题干&#xff1a; Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. She can eat up all the apples in the no…

mysql 磁盘组_有效管理 ASM 磁盘组空间

ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 错误会ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 …

【HDU - 1561】The more, The Better(树形背包,dp,依赖背包问题与空间优化,tricks)

题干&#xff1a; ACboy很喜欢玩一种战略游戏&#xff0c;在一个地图上&#xff0c;有N座城堡&#xff0c;每座城堡都有一定的宝物&#xff0c;在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因&#xff0c;有些城堡不能直接攻克&#xff0c;要攻克这些…

mysql判断域为空_MySQL EXPLAIN 字段说明

id查询或关联查询的顺序。如果没有子查询且只有一个查询&#xff0c;则为一个常数 1&#xff0c;表示第一步&#xff1b;如果有子查询&#xff0c;则子查询为 1&#xff0c;父查询为 2&#xff1b;相同的 id 查询顺序为自上而下&#xff1b;如果有子查询&#xff0c;不同 id 值…

【CodeForces - 618A】Slime Combining(二进制,思维)

题干&#xff1a; Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other…

mysql索引技术_MySQL索引类型

首先请查看不同引擎支持的索引类型&#xff1a;存储引擎简介 。聚集索引和非聚集索引概念见&#xff1a;聚集索引与非聚集索引 和 聚集索引 。 覆盖索引见&#xff1a;覆盖索引 。1. InnoDB的每一个表都会有一个聚集索引(第一索引&#xff0c;主键索引)。InnoDB按照主键进行聚集…

【CodeForces - 616C 】The Labyrinth点石成金(并查集,dfs)

题干&#xff1a; 小O无意间发现了一张藏宝图&#xff0c;它跟随藏宝图的指引来到了一个宫殿&#xff0c;宫殿的地板被分成了n*m块格子&#xff0c;每个格子上放置了金子或者石头 藏宝图告诉小O&#xff0c;它可以选择一块石头变成金子&#xff0c;并且带走与变化后的金子联通…

mysql连接方式左联_数据库中的左连接(left join)和右连接(right join)区别 | 改变自己...

Left Join / Right Join /inner join相关关于左连接和右连接总结性的一句话&#xff1a;左连接where只影向右表&#xff0c;右连接where只影响左表。Left Joinselect * from tbl1 Left Join tbl2 where tbl1.ID tbl2.ID左连接后的检索结果是显示tbl1的所有数据和tbl2中满足whe…

【蓝桥杯官网试题 - 真题训练】生命之树(树形dp)

题干&#xff1a; 在X森林里&#xff0c;上帝创建了生命之树。 他给每棵树的每个节点&#xff08;叶子也称为一个节点&#xff09;上&#xff0c;都标了一个整数&#xff0c;代表这个点的和谐值。 上帝要在这棵树内选出一个非空节点集S&#xff0c;使得对于S中的任意两个点a,…

jsp mysql 推荐算法_基于jsp+mysql+Spring+mybatis的SSM协同过滤音乐推荐管理系统(个性化推荐)...

运行环境: 最好是java jdk 1.8&#xff0c;我们在这个平台上运行的。其他版本理论上也可以。IDE环境&#xff1a; Eclipse,Myeclipse,IDEA都可以tomcat环境&#xff1a; 最好是Tomcat 7.x,8.x,9.x版本均可&#xff0c;理论上Tomcat版本不是太老都可以。&#xff0c;我们在这个环…

【牛客 - 157F】三轮(dp,分治fft)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/157/F 来源&#xff1a;牛客网 小k有一个三轮&#xff0c;它最多可以装105大小的东西 小k有n种商品&#xff0c;他要准备出摊了 每种商品体积为vi&#xff0c;都有105件 输出凑成1~m的体积的总方案…

项目进度计划甘特图_甘特图做项目进度计划的技巧?

原标题&#xff1a;甘特图做项目进度计划的技巧&#xff1f;甘特图怎么做项目进度计划&#xff1f;首先我们先了解一下&#xff0c;什么是甘特图。甘特图(Gantt chart)又称为横道图、条状图(Bar chart)&#xff0c;是由提出者亨利L甘特来命名的。甘特图通过条状图来显示项目&am…

【牛客 - 157C】PH试纸(前缀和,或权值线段树,主席树)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/157/C 来源&#xff1a;牛客网 题目描述 PH试纸&#xff0c;是一种检测酸碱度的试纸&#xff0c;试纸红色为酸性&#xff0c;蓝色为碱性。 HtBest有一个PH试纸&#xff0c;试纸被分成了n段&#xff0c…