Crashing Robots(水题,模拟)
1020: Crashing Robots
时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte
总提交: 207 测试通过:101
描述
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.
输入
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 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.
样例输入
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
样例输出
Robot 1 crashes into the wall
Robot 1 crashes into robot 2
OK
Robot 1 crashes into robot 2
题意:在一个长A宽B的矩形房间内有n个机器人,给m条指令判断机器人是否会和墙相撞或是否和其他机器人相撞。
此题就是纯粹的模拟,先把4个方向改为数字存,每次移动并记录,注意往左和右移。注意每一次移动都要判断是否相撞,而不是最后指令全部执行才判断。
#include "iostream"
using namespace std;
int a,b,n,m;
struct wxl
{
int x,y;
int s;
}ht[];
bool panduan(int h)//判断机器人是否会相撞
{
if(ht[h].x<=||ht[h].x>a||ht[h].y<=||ht[h].y>b)
{
cout<<"Robot "<<h<<" crashes into the wall"<<endl;
return false;
}
for(int i=;i<=n;i++)
{
if(i==h)continue;
if(ht[i].x==ht[h].x&&ht[i].y==ht[h].y)
{
cout<<"Robot "<<h<<" crashes into robot "<<i<<endl;
return false;
}
}
return true;
}
int main()
{
int i,t,p,j,k;
bool flag;
string str;
cin>>k;
while(k--)
{
cin>>a>>b>>n>>m;
for(i=;i<=n;i++)//将方向转为数字存
{
cin>>ht[i].x>>ht[i].y>>str;
if(str=="N")ht[i].s=;
else if(str=="E")ht[i].s=;
else if(str=="S")ht[i].s=;
else if(str=="W")ht[i].s=;
}
flag=true;//开始全为不会相撞
for(i=;i<m;i++)
{
cin>>t>>str>>p;//t为机器人,str表示往哪个方向,p表示前进几步
if(str=="F")//F最为简单,先判断
{
if(flag)
{
for(j=;j<p;j++)
{
if(ht[t].s==)ht[t].y++;
if(ht[t].s==)ht[t].x++;
if(ht[t].s==)ht[t].y--;
if(ht[t].s==)ht[t].x--;
flag=panduan(t);//此处开始判断
if(!flag)break;//因为在函数中写了输出函数,此处直接退出
}
}
}
else if(str=="L")
{
ht[t].s=(ht[t].s-p%+)%;//注意
}
else if(str=="R")
{
ht[t].s=(ht[t].s+p%)%;
}
}
if(flag)cout<<"OK"<<endl;
}
}
Crashing Robots(水题,模拟)的更多相关文章
- POJ 2632 Crashing Robots (坑爹的模拟题)
		Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ... 
- CodeForces 686A Free Ice Cream (水题模拟)
		题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ... 
- ACM: NBUT 1105  多连块拼图 - 水题 - 模拟
		NBUT 1105 多连块拼图 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format: Practice Appoint ... 
- CodeForces 342B Xenia and Spies (水题模拟,贪心)
		题意:给定 n 个间谍,m个区间,一个 s,一个f,然后从 s开始传纸条,然后传到 f,然后在每个 t 时间在区间内的不能传,问你最少的时间传过去. 析:这个题,就模拟一下就好,贪心策略,能传就传,找 ... 
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
		B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ... 
- Codeforces Round #350 (Div. 2) B. Game of Robots 水题
		B. Game of Robots 题目连接: http://www.codeforces.com/contest/670/problem/B Description In late autumn e ... 
- CodeForces 339B Xenia and Ringroad(水题模拟)
		题意:给定 n 个地方,然后再给 m 个任务,每个任务必须在规定的地方完成,并且必须按顺序完成,问你最少时间. 析:没什么可说的,就是模拟,记录当前的位置,然后去找和下一个位置相差多长时间,然后更新当 ... 
- CodeForces 723B Text Document Analysis (水题模拟)
		题意:给定一行字符串,让你统计在括号外最长的单词和在括号内的单词数. 析:直接模拟,注意一下在左右括号的时候有没有单词.碰到下划线或者括号表示单词结束了. 代码如下: #pragma comment( ... 
- CodeForces 731B Coupons and Discounts (水题模拟)
		题意:有n个队参加CCPC,然后有两种优惠方式,一种是一天买再次,一种是买两天,现在让你判断能不能找到一种方式,使得优惠不剩余. 析:直接模拟,如果本次是奇数,那么就得用第二种,作一个标记,再去计算下 ... 
随机推荐
- Random-Forest-Python
			1. 近期目标,实现随机森林进行点云分类 1)学习阶段: [干货]Kaggle 数据挖掘比赛经验分享 Kaggle Machine Learning Competition: Predicting T ... 
- linux运维需要掌握什么知识?linux运维学习路线
			linux运维需要掌握什么知识?这个问题算是老生常谈了,但是本人认为知道需要掌握什么知识不是重点,重点是我们需要知道运维是做什么的?再来根据工作需求去讨论需要学习什么知识才是正途,须知知识是学不完的, ... 
- python安装画图模块pillow
			步骤一: install pillow (注意导入是 import PIL ) 步骤二:如果pycharm中import选择不到,则需要在settings中导入下 ... 
- 用微信小程序连接leancloud数据库注意事项~
			具体步骤转载如下: 官网教程 大佬提示 注意事项: 1.下载的av-weapp-min.js,需要放在当前项目名称的子目录pages下 2.如上述教程,需要注册leancloud和AppID,并写在a ... 
- mySQL的行转列
			因为MYSQL里边没有 PIVOT 现记录: 原表格: mysql语句: SELECT MAX(CASE WHEN corol='红' THEN NUM else 0 END) A ... 
- Object类的wait方法带参数和notifyAll方法
			相当于sleep( 5000 ) , 效果一样: 
- Github-记账本
- 20190410Linux中磁盘管理及LVM(week2day1)
			Linux磁盘管理及LVM讲解(week2_day2) 硬盘接口 从整体的角度上,硬盘接口分为IDE.SATA.SCSI和SAS四种,IDE接口硬盘多用于家用产品中,也部分应用于服务器,SCSI接 ... 
- Mac休眠后解决卡死转圈问题
			不知什么时候MacBookPro出现盒盖休眠后Wifi连不上,卡死,转圈问题 在网上搜索解决了下,具体什么原因先不用管了,有时间升级下系统 sudo killall airportd 应该是Mojav ... 
- Python中 sys.argv[]的用法简明解释
			sys.argv[]就是一个从程序外部获取参数的桥梁,这个“外部”很关键.因为我们从外部取得的参数可以是多个,所以获得的是一个列表(list),也就是说sys.argv其实可以看作是一个列表,所以才能 ... 
