题目链接: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(较为繁琐的模拟)的更多相关文章

  1. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  2. POJ 2632 Crashing Robots (坑爹的模拟题)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6599   Accepted: 2854 D ...

  3. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  4. poj 2632 Crashing Robots

    点击打开链接 Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6655   Accepted: ...

  5. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

  6. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  7. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  8. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  9. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

随机推荐

  1. 怎样删除在Github中创建的项目

    像我这种刚開始学习的人总会不可避免的创建了一些測试性的项目.随后自然就是要删除了.那么该怎样删除呢? 你此刻可能处于这个界面: 也可能处于这个界面: 假设是第一个界面直接点击右側的"Sett ...

  2. 使用Visual Studio将Objective-C编译C++

    编译器支持 谷歌和苹果应用Clang由于他们的C++前端.为了使他们的执行代码Windows上,微软不得不Visual C++C2和Clang结合起来. (Clang是一个C语言.C++.Object ...

  3. Oracle 11g RAC OCR 与 db_unique_name 配置关系 说明

    一. 问题一 在做RAC standby 的alert log里发现如下错误: SUCCESS: diskgroup DATA was mounted ERROR: failed toestablis ...

  4. 演练5-3:Contoso大学校园管理系统3

    在前面的教程中,我们使用了一个简单的数据模型,包括三个数据实体.在这个教程汇中,我们将添加更多的实体和关系,按照特定的格式和验证规则等自定义数据模型. Contoso大学校园管理系统的数据模型如下. ...

  5. android 4.0后不允许屏蔽掉home键

    屏蔽home键的方法 // 屏蔽掉Home键 public void onAttachedToWindow() { this.getWindow().setType(WindowManager.Lay ...

  6. 给你的Cordova HybridApp加入Splash启动页面

    如今最新的Cordova 3以上的版本号支持启动画面了,是通过cordova插件实现的. 眼下Splash插件支持android,ios,blackberry等多个平台. 加入插件等步骤例如以下: 加 ...

  7. XSS学习笔记(四)-漏洞利用全过程

    <script type="text/javascript" reload="1">setTimeout("window.location ...

  8. vi 快捷键积累

    依据自己用到的.或者还没记住的.或者用的时候忘了的,慢慢积累. 一.全选复制粘贴. 全选: ggVG // 凝视: gg 光标移到首行 V 进入Visual(可视)模式 G 光标移到最后一行全选 选中 ...

  9. Ch04 充满动作的控制器

    4.1  考察控制器和动作 4.1.1  IController与控制器基类 4.1.2  如何形成动作方法 4.2  哪些应该放在动作方法中 4.2.1  手动映射视图模型 4.2.2  输入验证 ...

  10. Study notes for Latent Dirichlet Allocation

    1. Topic Models Topic models are based upon the idea that documents are mixtures of topics, where a ...