链接: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. [leetcode]Reverse Words in a String @ Python

    原题地址:https://oj.leetcode.com/problems/reverse-words-in-a-string/ 题意: Given an input string, reverse ...

  2. centos7 开机自动连网

    新安装好的CentOS7桌面版,默认的网络都是关闭的,在图形页面中,开启后,重启后网络又关闭了.下面配置开机自动连网. 工具/原料   CentOS7.2 方法/步骤     首先打开终端,用ifco ...

  3. windows10-64位安装OpenSSL详细教程(转载)

    相关软件下载地址: 1.ActivePerl 5.26.1:https://www.activestate.com/activeperl/downloads 2.openssl-1.1.0g:http ...

  4. mysql 字符串按照数字类型排序

    一个varchar,char的字段 存放 1+,12- ,11等字符串将字段*1或者+0可以将MySQL字符串字段按数值排序 order by 字段名称+0 desc/asc的形式进行排序 order ...

  5. 文本分类(六):使用fastText对文本进行分类--小插曲

    http://blog.csdn.net/lxg0807/article/details/52960072 环境说明:python2.7.linux 自己打自己脸,目前官方的包只能在linux,mac ...

  6. ML、DL相关资源

    1. http://x-algo.cn/index.php/category/nlp/

  7. mahout安装

    mahout是hadoop的一种高级应用.运行mahout需要提前安装好hadoop.hadoop的安装网上很多.而且也不复杂,这里不再讲述.这里默认hadoop已经安装完成. 1:下载二进制解压安装 ...

  8. Magento错误 Illegal scheme supplied, only alphanumeric characters are permitted

    1.检查表core_config_data 'web/unsecure/base_url' 和'web/secure/base_url' 的值是否是正确的链接地址 2.删除系统目录var下所有子目录及 ...

  9. java 让图片变黑白

    import java.awt.Image;import java.awt.color.ColorSpace;import java.awt.image.BufferedImage;import ja ...

  10. 什么是哈希码(HashCode)

    什么是哈希码(HashCode) 在Java中,哈希码代表对象的特征. 例如对象 String str1 = “aa”, str1.hashCode= 3104 String str2 = “bb”, ...