题目链接: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. 西安力邦智能医疗&amp;可穿戴设备沙龙--第1期---苹果HealthKit、谷歌GoogleFit来袭,智能医疗要爆发吗?

    背    景: "可穿戴设备"成为2014的行业热点,从Google Glass到苹果iWatch, 越来越多的企业推出了包含眼镜.腕带.鞋等各种可穿戴设备,"可穿戴&q ...

  2. NGUI出现Shader wants normals, but the mesh UIAtlas doesn&#39;t have them

    NGUI出现Shader wants normals, but the mesh UIAtlas doesn't have them,没有网格法线,打开UI Root上 UIPanel组建上的 Nor ...

  3. 自己定义progressdialog,改善用户体验

    自己定义progressdialog,改善用户体验 效果图: 详细实现方式: 1.定义Dialog的Layout布局 2.设置动画anim 3.创建自己定义dialog的样式 4.创建共同拥有方法来控 ...

  4. ZOJ 3483 简单if-else

    提醒:答案要约分,不然会错! #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  5. 09-IOSCore - 应用互动、UIImagePickerController

    一.调用系统程序/服务 1. 应用互动数据权限 1) 跟自己本地数据交互 2) 跟网络服务器/云数据交互 3) 跟系统数据服务交互 4) 跟其它应用程序交互 2. 基础 URL 统一资源定位 一个特殊 ...

  6. QTableWidget排序问题

    今天写代码,发现Qt4中QTableWidget显示查询结果数据时存在一个问题,具体原因不知道是用法不对还是QTableWidget本身存在的bug.现象如下: 1.      查询,能正常显示查询结 ...

  7. CSS+DIV入门第一天基础视频 CSS选择器层叠性和继承性

    大家好,我是小强老师, 现在网上的CSS+DIV视频,要么讲的太深,要么太浅,很多初学的同学们总是遇到困难,今天小强老师专门给大家准备了css课程的视频.带你从零基础学习CSS+DIV一直到能独立完成 ...

  8. 使用ffmpeg视频编码过程中踩的一个坑

           今天说说使用ffmpeg在写视频编码程序中踩的一个坑,这个坑让我花了好多时间,回头想想,非常多时候一旦思维定势真的挺难突破的.以下是不对的编码结果:                   ...

  9. cloudflare的新waf,用Lua实现的

    我们使用nginx贯穿了我们的网络,做前线web服务,代理,流量过滤.在某些情况下,我们已经扩充了nginx上我们自己的模块的核心C代码,但近期我们做了一个重大举措,与nginx结合使用lua 差点儿 ...

  10. IOS学习之segmented control

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/27086877 作者:小马 什么是segmented control? 先上几张图: ...