【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,一经查实,立即删除!

相关文章

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

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

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;然后点击上方的“编辑用户”按…

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;要攻克这些…

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

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

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;我们在这个环…

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

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

wp config.php mysql_WordPress手动配置wp-config.php文件

前不久在WordPress技术群里看到有人在安装网站程序的时候出现了系统不能自动配置wp-config.php文件的问题&#xff0c;那么这个时候就需要我们手动进行配置了。问题描述&#xff1a;如果自动创建未能成功&#xff0c;不用担心&#xff0c;您要做的只是将数据库信息填入配置文件…

thinkphp使用echarts_Thinkphp 与Echarts-php 使用

这里推荐大家使用composer 依赖管理工具 导入Echarts-php库{"name": "hisune/echarts-php","version": "1.0.10","version_normalized": "1.0.10.0","source": {"type": "git",&qu…

创建文件夹 java_java怎么建文件夹

Java文件类以抽象的方式代表文件名和目录路径名。该类主要用于文件和目录的创建、文件的查找和文件的删除等。File对象代表磁盘中实际存在的文件和目录。下面我们来看一下java中创建文件夹的方法&#xff1a;示例&#xff1a;package com.zz;import java.io.File;import java.i…

【Gym - 101986F】Pizza Delivery(Dijkstra最短路,建图方式,反向建图,Tarjan求桥,图论模板)

题干&#xff1a; 题目大意&#xff1a; 一个有向图&#xff0c;编号1~n的n个点&#xff0c;m条边&#xff0c;规定1为起点&#xff0c;2为终点&#xff0c;问对于每一条边&#xff0c;反转它的方向&#xff0c;最短路会不会发生改变&#xff0c;如果变短了&#xff0c;输出HA…

【CF#505B】Mr. Kitayuta's Colorful Graph (并查集或Floyd或BFS)

题干&#xff1a; Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to p…

java data jpa_Spring Data JPA(一)简介

Spring Data JPA介绍可以理解为JPA规范的再次封装抽象&#xff0c;底层还是使用了Hibernate的JPA技术实现&#xff0c;引用JPQL(Java Persistence Query Language)查询语言&#xff0c;属于Spring整个生态体系的一部分。随着Spring Boot和Spring Cloud在市场上的流行&#xff0…

【CodeForces - 438D】The Child and Sequence(线段树区间取模操作)

题干&#xff1a; At the childrens day, the child came to Pickss house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the sequ…

java 自定义xml_6.1 如何在spring中自定义xml标签

dubbo自定义了很多xml标签&#xff0c;例如&#xff0c;那么这些自定义标签是怎么与spring结合起来的呢&#xff1f;我们先看一个简单的例子。一 编写模型类1 packagecom.hulk.testdubbo.model;23 public classHero {4 privateString name;5 private intage;67 publicString ge…

java 模块设计模式_Java9模块化学习笔记二之模块设计模式

模块设计的原则:1、防止出现编译时循环依赖(主要是编译器不支持)&#xff0c;但运行时是允许循环依赖的&#xff0c;比如GUI应用2、明确模块的边界几种模块设计:API模块&#xff0c;聚合模块(比如java.base)可选依赖两种方式:1、可选的编译时依赖(类似于maven的provided scope)…

java 手写签名_Android 自定义View手写签名并保存图片

GIF压缩有问题&#xff0c;运行很顺滑&#xff01;&#xff01;&#xff01;1.自定义View——支持设置画笔颜色&#xff0c;画笔宽度&#xff0c;画板颜色&#xff0c;清除画板&#xff0c;检查是否有签名&#xff0c;保存画板图片(复制粘贴可直接使用)/*** Created by YyyyQ o…

【2019第十届蓝桥杯省赛C/C++B组题解】(非官方题解)

A。 数数题。 答案&#xff1a;490 B。 26进制模拟。 答案&#xff1a;BYQ C。 类似fib数列求值&#xff0c;递推一下就好。 答案&#xff1a;4659 D。 注意两个坑点&#xff0c;一个是正整数&#xff0c;所以枚举要从1开始。第二个坑点是互不相同的&#xff0c;为了达到这…