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 ...
随机推荐
- [置顶] 如何判断两个IP大小关系及是否在同一个网段中
功能点 判断某个IP地址是否合法 判断两个IP地址是否在同一个网段中 判断两个IP地址的大小关系 知识准备 IP协议 子网掩码 Java 正则表达式 基本原理 IP地址范围 0.0.0.0- 255 ...
- 关于JSP post请求乱码的问题
解决用户请求页面乱的问题 1. 修改apache下的config文件夹下的server.XML文件 <Connector connectionTimeout="20000" ...
- 转:关于http server - 来自百度知道,留存备读
web server 目 录 1名词解释 2应用程序服务器与web服务器 2.1 Web服务器(Web Server) 2.2 带应用程序服务器的Web服务器 2.3 警告(caveats) ...
- [转]linux下iftop工具的安装与使用详解(图文)——实时的网络流量,监控TCP/IP连接(单机)
原文链接:http://www.jbxue.com/LINUXjishu/10735.html 在linux中监控系统资源.进程.内存占用等信息,可以使用top命令.查看网络状态可以使用netstat ...
- C语言数据结构-创建链表的四种方法
结点类型: typedef int datatype; typedef struct NODE{ datatype data; struct NODE *next; }Node,*LinkList; ...
- 演练5-7:Contoso大学校园管理系统(实现继承)
***操作视频下载:1 *** 在上一次教程中,你已经能够处理并发异常.这个教程将会展示如何在数据模型中实现继承. 在面向对象的程序设计中,你可以通过继承来清除冗余的代码.在这个教程中,你将要 ...
- Qt 状态机框架学习(没学会)
Qt状态机框架是基于状态图XML(SCXML) 实现的.从Qt4.6开始,它已经是QtCore模块的一部分.尽管它本身是蛮复杂的一套东西,但经过和Qt的事件系统(event system).信号槽(s ...
- ios内存管理2-对象之间的内存管理
同之前一样,新建一个基于命令行的工程,在新建一个Student类和一个Book类 编写如下代码: Student.h // // Student.h // 内存管理2-对象之间的内存管理 // // ...
- HDOJ 5071 Chat 模拟
大模拟: 1>saygoodbye要先对 always on top 的人说 2>对没有说过话的不要说good bye 3>用long long Chat Time Limit: 2 ...
- PHP - 自定义函数
第7章 自定义函数 学习要点: 1.标准函数 2.自定义函数 3.文件包含 4.魔法常量 一般来讲,冗余的代码都是不好的.一而再,再而三地重写代码不仅浪费时间,从布局结构角度看也显得粗制滥造.与所有优 ...