链接:poj 2632

题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数,

L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一米

若前进时机器i撞到机器j,输出“Robot i crashes into robot j ”

若机器走出了n*m的房间,输出“Robot i crashes into the wall ”

当出现上述情况。仅仅需输出第一次出现上述的情况

若全部指令运行完,全部机器都没碰到上述情况,输出“OK”

思路:理解题意后,简单模拟就能够了

注意:行和列要分清,题中都是先输入列,还要注意机器的方向

#include<stdio.h>
#include<string.h>
int x[4]={1,0,-1,0},y[4]={0,1,0,-1}; //北东南西
int num,m,n,vis[101][101];
struct stu
{
int r,c,dir;
}rob[105];
int rob_go(int k,char c,int time)
{
int i,ri,ci;
if(c=='L'){
time%=4;
rob[k].dir=(rob[k].dir+4-time)%4;
}
else if(c=='R'){
time%=4;
rob[k].dir=(rob[k].dir+time)%4;
}
else if(c=='F'){
ri=rob[k].r;
ci=rob[k].c;
vis[ri][ci]=0;
while(time--){
ri+=x[rob[k].dir];
ci+=y[rob[k].dir];
if(vis[ri][ci]){ //若撞到某机器,返回该机器的编号
for(i=1;i<=num;i++)
if(ri==rob[i].r&&ci==rob[i].c)
return i;
}
}
if(ri<1||ri>n||ci<1||ci>m)
return -1; //用-1标记机器走到了墙里
rob[k].r=ri;
rob[k].c=ci;
vis[ri][ci]=1;
}
return 0;
}
int main()
{
int T,i,ins,flag,k,time;
char c;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d",&m,&n,&num,&ins);
memset(vis,0,sizeof(vis)); //标记此处机器是否存在。0代表不存在
for(i=1;i<=num;i++){
scanf("%d %d %c",&rob[i].c,&rob[i].r,&c);
vis[rob[i].r][rob[i].c]=1; //1表示此处有机器
if(c=='N')
rob[i].dir=0;
else if(c=='E')
rob[i].dir=1;
else if(c=='S')
rob[i].dir=2;
else if(c=='W')
rob[i].dir=3;
}
flag=0;
i=0;
while(ins--){
scanf("%d %c %d",&k,&c,&time);
if(!flag){
flag=rob_go(k,c,time);
if(flag&&!i) //若撞到其它机器或走到墙里,其它就不必推断了
i=k; //记录第一次未安全运行完指令的机器
}
}
if(flag==0)
printf("OK\n");
else if(flag==-1)
printf("Robot %d crashes into the wall\n",i);
else
printf("Robot %d crashes into robot %d\n",i,flag);
}
return 0;
}

poj 2632 Crashing Robots(模拟)的更多相关文章

  1. poj 2632 Crashing Robots 模拟

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

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

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

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

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

  4. 模拟 POJ 2632 Crashing Robots

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

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

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

  6. poj 2632 Crashing Robots

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

  7. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

  8. poj 2632 Crashing Robots_模拟

    做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...

  9. Poj OpenJudge 百练 2632 Crashing Robots

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

随机推荐

  1. Server 2008 R2大改造变成梦幻Win7系统

    在此之前先补充一下知识Windows Server 2008和Windows Server 2008 R2的不同之处Windows Server 2008是基准与Vista的内核构建的,支持X86框架 ...

  2. RxJava【变换】操作符 map flatMap concatMap buffer MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. 配置nginx到后端服务器负载均衡

    nginx和haproxy一样也可以做前端请求分发实现负载均衡效果,比如一个tomcat服务如果并发过高会导致处理很慢,新来的请求就会排队,到一定程度时请求就可能会返回错误或者拒绝服务,所以通过负载均 ...

  4. Linq-Contains查询

    customers.Where(c => c.Name.Contains("john"));

  5. VS2013开发asmx接口根据ID查询对象

    代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syst ...

  6. (转)溶解shader

    游戏中物体腐化消失,燃烧消失时,会有从局部慢慢消失的效果,然后配合一些粒子特效,就能达到非常好的美术效果.类似效果如下: 注:_DissColor为溶解主色,_AddColor为叠加色,按照溶解的移动 ...

  7. Anroid 解决小米和魅族不能在mac上调试

    第一种方法 1.mac->关于本机->系统报告->usb->copy厂商ID** 2.cmd->echo " 0x2a45" >> ~/. ...

  8. OpenGL ES 3.0 and libGLESv2

    note that libGLESv2 is the recommended Khronos naming convention for the OpenGL ES 3.0 library. This ...

  9. ElasticSearch无法启动

    安装了ElasticSearch5.5.1后,每次启动服务的时候,都是启动了一下就自动停止了.查看了一下EventViewer, 错误信息如下: Application: elasticsearch. ...

  10. ERROR: In &lt;declare-styleable&gt; MenuView, unable to find attribute android:preserveIconSpacing

    eclipse  sdk从低版本号切换到高版本号sdk的时候   v7包会包这个错ERROR: In <declare-styleable> MenuView, unable to fin ...