链接: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. IIS(互联网信息服务)

    ylbtech-Miscellaneos:IIS(互联网信息服务) IIS是Internet Information Services的缩写,意为互联网信息服务,是由微软公司提供的基于运行Micros ...

  2. 查看sql执行的情况

    今天同事让看一个sql,无意中学到一个查看sql执行情况的命令,以前都是傻傻的等的,今后不用了 SELECT percent_complete FROM sys.dm_exec_requests

  3. go语言之进阶篇 channel介绍

    1.channel介绍 和map类似,channel也一个对应make创建的底层数据结构的引用. 当我们复制一个channel或用于函数参数传递时,我们只是拷贝了一个channel引用,因此调用者何被 ...

  4. 会动的文字Marquee应用(转)

    想要做个滚动公告,看了网上的教程,无一不是很恐怖的场频啊java语言编制的JS,或者就是各种复杂,无意中发现了Marquee这东西,用了一下,很简单,只需两行代码,即可以实现很好的效果,特此分享一下. ...

  5. [leetcode]Gray Code @ Python

    原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...

  6. delphi判断.net FrameWork是否已安装

    判断系统中.NET FrameWork已安装版本的方法很多,比如检查C:\Windows\Microsoft.NET\Framework\下的子目录,但是子目录往往是包含版本号,比如v2.0.5072 ...

  7. 学界 | Yann LeCun新作,中日韩文本分类到底要用哪种编码?

    https://www.wxwenku.com/d/102093756 AI科技评论按:前几天,Yann LeCun与其学生 张翔在arXiv上发表了一篇新作「Which Encoding is th ...

  8. Mac下brew/memcached/nginx/iterm/zsh的安装

    brew  https://www.cnblogs.com/fireworld/p/8609190.html memcached https://blog.csdn.net/whereismatrix ...

  9. webstorm和intellij idea下如何自动编译sass和scss文件

    webstorm和intellij idea下如何自动编译sass和scss文件 https://segmentfault.com/a/1190000008996504 https://www.jia ...

  10. CMake can't find GLEW

      Q: I'm on Windows and there is a FindGLEW.cmake file in my CMake modules folder, presumably put th ...