POJ 2632 Crashing Robots(较为繁琐的模拟)
题目链接:http://poj.org/problem?id=2632
题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果:
1.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.) 撞墙
2.Robot i crashes into robot j, if robots i and j crash, and i is the moving robot. 两个机器人相撞
3.OK, if no crashing occurs.没有发生任何碰撞
思路:模拟模拟~~
用一个结构体变量记录每个robet的信息。。具体看代码吧:
#include<iostream>
#include<fstream>
using namespace std;
struct node
{
int id;
int x;//机器人的坐标
int y;
char ch;//机器人的方向
}robet[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int X,Y;
cin>>X>>Y;
int numrobet,times;
cin>>numrobet>>times;
int i;
for(i=; i<=numrobet; i++)
{
robet[i].id=i;
cin>>robet[i].x>>robet[i].y>>robet[i].ch;//机器人的初始位置及朝向
}
int id,step,j,tage=,k,r;
char direction;
for(i=;i<=times;i++)
{
cin>>id>>direction>>step;//编号为id的机器人的操作和重复操作的次数
for(j=;j<=numrobet;j++)
{
if(robet[j].id==id)
{
for(k=;k<step;k++)
{
if(tage==)
break;
else if(tage==)//机器人的位置和方向的改变
{
if(robet[j].ch=='N')//如果机器人一开始朝北
{
if(direction=='F')//操作“F”,向北进一
robet[j].y+=;
else if(direction=='L')//操作“L”,向左转
robet[j].ch='W';
else if(direction=='R')//操作“R”,向右转
robet[j].ch='E';
}
else if(robet[j].ch=='E')
{
if(direction=='F')
robet[j].x+=;
else if(direction=='L')
robet[j].ch='N';
else if(direction=='R')
robet[j].ch='S';
}
else if(robet[j].ch=='W')
{
if(direction=='F')
robet[j].x-=;
else if(direction=='L')
robet[j].ch='S';
else if(direction=='R')
robet[j].ch='N';
}
else if(robet[j].ch=='S')
{
if(direction=='F')
robet[j].y-=;
else if(direction=='L')
robet[j].ch='E';
else if(direction=='R')
robet[j].ch='W';
}
}
if(robet[id].x<=||robet[id].y<=||robet[id].x>X||robet[id].y>Y)
{
cout<<"Robot "<<id<<" crashes into the wall"<<endl;
tage=;
break;
}//判断撞墙
else
{
for(r=; r<=numrobet; r++)
{
if(robet[r].x==robet[id].x&&robet[r].y==robet[id].y&&r!=id)
{
cout<<"Robot "<<id<<" crashes into robot "<<r<<endl;
tage=;
}
}
if(tage==)
break;
}//判断两个机器人相撞
}
}
}
}
if(tage==)
cout<<"OK"<<endl;
}
return ;
}
POJ 2632 Crashing Robots(较为繁琐的模拟)的更多相关文章
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
随机推荐
- Python 第五篇(下):系统标准模块(shutil、logging、shelve、configparser、subprocess、xml、yaml、自定义模块)
目录: shutil logging模块 shelve configparser subprocess xml处理 yaml处理 自定义模块 一,系统标准模块: 1.shutil:是一种高层次的文件操 ...
- Python 第五篇(上):算法、自定义模块、系统标准模块(time 、datetime 、random 、OS 、sys 、hashlib 、json和pickle)
一:算法回顾: 冒泡算法,也叫冒泡排序,其特点如下: 1.比较相邻的元素.如果第一个比第二个大,就交换他们两个. 2.对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应 ...
- java--匿名类
匿名类的使用 package Test; abstract class C525{ abstract void foo(); } class B525{ // 局部类只能访问外包方法中的final成员 ...
- gitflow 在windows下的安装方法
Git flow是git的一个扩展集,它基于Vincent Driessen的分支模型,可以用来简化代码的版本发布流程. 本文讲述如何为msysgit安装git flow. 下载getopt.exe ...
- Java基础02 方法与数据成员
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在Java基础01 从HelloWorld到面向对象,我们初步了解了对象(obje ...
- Windows窗体透明效果
虚拟机里的win7也想实现透明效果, 使用vitrite这个免费软件就可以了.
- POJ - 1006 Biorhythms 周期相遇 两个思路程序
Description Some people believe that there are three cycles in a person's life that start the day he ...
- WEB服务器、应用程序服务器区别
WEB服务器.应用程序服务器.HTTP服务器有何区别?IIS.Apache.Tomcat.Weblogic.WebSphere都各属于哪种服务器,这些问题困惑了很久,今天终于梳理清楚了: Web服务器 ...
- POJ3436 ACM Computer Factory 【最大流】
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5412 Accepted: 1 ...
- <转载>如何解决子级用float浮动父级div高度不能自适应的问题
转载:http://www.kwstu.com/ArticleView/divcss_2013101582430202 解决子级对象使用css float浮动 而父级div不能自适应高度,不能被父级内 ...