题目链接: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. 怎样为ubuntu eclipse 添加 GBK字符集

    以前没有发现,最近把自己的代码靠到同学电脑上运行报错,发现是字符集的问题,一般来说 eclipse默认的是GBK编码,而ubuntu上默认是没有GBK编码的,所以ubuntu eclipse 上自然就 ...

  2. 学习MongoDB 二:MongoDB加入、删除、改动

    一.简单介绍 MongoDB是一个高性能.开源.无模式的文档型数据库,是当前NoSQL数据库产品中最热门的一种.数据被分组存储在数据集中,被称为一个集合(Collenction)和对于存储在Mongo ...

  3. [转]Centos 6.5 优化 一些基础优化和安全设置

    关于CentOS服务器的优化下文作为参考. 本文 centos 6.5 优化 的项有18处: 1.centos6.5最小化安装后启动网卡2.ifconfig查询IP进行SSH链接3.更新系统源并且升级 ...

  4. java--线程状态

    1.新建状态 Thread t1 = new Thread(); 创建之后,就已经有了相应的内存和其他资源,但是还是处于不可运行状态. 2.就绪状态 当一个线程使用.start()启动之后就处于就绪状 ...

  5. AlphaMobileControls介绍

    大家在开发wince程序或者windows mobile程序时还在为丑陋的界面着急吗?AlphaMobileControls可以帮你解决这些方案.当然如果你是高手可以自己去实现一些特殊的功能,自己定义 ...

  6. 基于visual Studio2013解决算法导论之006最大堆排序

     题目 最大堆排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #i ...

  7. ESRI Shapefiles (SHP)

    ESRI Shapefiles (SHP) Also known as ESRI ArcView Shapefiles or ESRI Shapefiles. ESRI is the company ...

  8. ASIHTTPRequest-插件的使用

    链接地址:http://blog.sina.com.cn/s/blog_7b9d64af0101e5uf.html 一.什么是ASIHTTPRequest   ASIHTTPRequest 插件是一个 ...

  9. hadoop部署、启动全套过程

    Hadoop是Apache基金会的开源项目,为开发者提供了一个分布式系统的基础架构,用户可以在不了解分布式系统的底层细节的情况下开发分布式的应用,充分利用集群的强大功能,实现高速运算和存储.Hadoo ...

  10. 前端project师,确定你的目标吧!无能的人才管他叫命运

    导语: 你为自己定过一个不靠谱的目标,是20年前的事了吧. 长大你想干什么?你的回答是什么?现在实现了吗? 如今,你每天都坐在同一个格子间的同一个电脑前,会不会感到每天都像是在复印,感到前途是模糊的, ...