http://poj.org/problem?id=2632

#include<cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int A,B,n,m;
int robot[101][3];
char rbuff[10];
int dir[255];
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int action[101][3];
int tx,ty;
int ansr;
bool between(int aim,int gap){
int sx=robot[gap][0];
int sy=robot[gap][1];
int mingx=min(sx,tx);
int maxgx=max(sx,tx);
int mingy=min(sy,ty);
int maxgy=max(sy,ty);
int ax=robot[aim][0];int ay=robot[aim][1];
if(ax>=mingx&&ax<=maxgx&&ay>=mingy&&ay<=maxgy){
if(ansr==0)ansr=aim;
else {
if(abs(robot[ansr][0]-sx)>=abs(ax-sx)&&abs(robot[ansr][1]-sy)>=abs(ay-sy)){
ansr=aim;
}
}
return true;
}
return false;
}
void solve(){
ansr=0;
for(int i=0;i<m;i++){
int rob=action[i][0];
int rep=action[i][1];
if(action[i][2]==0){
robot[rob][2]=(robot[rob][2]+4-rep%4)%4;
}
else if(action[i][2]==1){
robot[rob][2]=(robot[rob][2]+rep%4)%4;
}
else{
bool fl=false;
tx=robot[rob][0]+rep*dx[robot[rob][2]];
ty=robot[rob][1]+rep*dy[robot[rob][2]];
for(int j=1;j<=n;j++){
if(j==rob)continue;
if(between(j,rob)){
fl=true;
}
}
if(fl){
printf("Robot %d crashes into robot %d\n",rob,ansr);return ;
}
if(tx<1||tx>A||ty<1||ty>B){
printf("Robot %d crashes into the wall\n",rob);return ;
}
robot[rob][0]=tx;
robot[rob][1]=ty;
}
}
puts("OK");
} int main(){
dir['N']=0;dir['E']=1;dir['S']=2;dir['W']=3;
dir['L']=0;dir['R']=1;dir['F']=2;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&A,&B,&n,&m);
for(int i=1;i<=n;++i){
scanf("%d%d%s",robot[i],robot[i]+1,rbuff);
robot[i][2]=dir[rbuff[0]];
}
for(int i=0;i<m;i++){
scanf("%d%s%d",action[i],rbuff,action[i]+1);
action[i][2]=dir[rbuff[0]];
}
solve();
}
return 0;
}

  

POJ 2632 Crashing Robots 模拟 难度:0的更多相关文章

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

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

  2. poj 2632 Crashing Robots 模拟

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

  3. 模拟 POJ 2632 Crashing Robots

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

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

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

  5. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  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 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  9. poj 2632 Crashing Robots_模拟

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

随机推荐

  1. css3,环绕圆环 loading,小组件

    一个loading的小组件, 给其他模块调用.先上图 type:cat type:ball 第一幅loading,老鼠是一个圆形的背景图片,已经转成base64. 小猫也是图片 也已经转成base64 ...

  2. c#获取url请求的返回值(转)

    有两种方式获取. 方法一: /// <summary> /// 获取url的返回值 /// </summary> /// <param name="url&qu ...

  3. Git学习(3)创建版本库

    什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或 ...

  4. MonkeyRunner学习(1)测试连接

    前期的环境搭建详见:http://www.cnblogs.com/peng-lan/p/5388488.html 1.打开模拟器 打开模拟器有两种方法,正常的在eclipse 中启动就不介绍了 另一种 ...

  5. md5加密过程

    import java.beans.Encoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmE ...

  6. OpenCV图像处理中常用函数汇总(1)

    //俗话说:好记性不如烂笔头 //用到opencv 中的函数时往往会一时记不起这个函数的具体参数怎么设置,故在此将常用函数做一汇总: Mat srcImage = imread("C:/Us ...

  7. html5中插入视频和音频

    <audio src="1.mp3" controls></audio> <video src="1.mp4" controls& ...

  8. 栅栏 CyclicBarrier

    java.util.concurrent.CyclicBarrier 类是一种同步机制,它能够对处理一些算法的线程实现同步.换句话讲,它就是一个所有线程必须等待的一个栅栏,直到所有线程都到达这里,然后 ...

  9. js控制手机号码中间用星号代替

    $("#tel").html($("#tel").substring(0,3)+"****"+$("#tel").sub ...

  10. centos nginx 安装

    1.下载 wget http://nginx.org/download/nginx-1.7.8.tar.gz 2.解压 tar -zxvf nginx-1.7.8.tar.gz 3.切换目录 cd n ...