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. [转发] 老叶观点:MySQL开发规范之我见

    原文: http://imysql.com/2015/07/23/something-important-about-mysql-design-reference.shtml 老叶观点:MySQL开发 ...

  2. 使用连接来代替in和not in(使用外连接技巧)

    比如:表A里面的一个字段叫做MOBILE 里面存的记录如下 : 123456781 表B里面的一个字段也叫做MOBILE里面存的记录如下 12341910   (1)我们要查询一下A和B里面都有的,以 ...

  3. Logger日志级别说明及设置方法、说明 (zhuan)

    http://blog.csdn.net/rogger_chen/article/details/50587920 ****************************************** ...

  4. SO_REUSEADDR 和 SO_REUSEPORT

    大部分内容来自stackoverflow上的回答:Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they m ...

  5. commonJS — 全局操作(for Window)

    for Window github: https://github.com/laixiangran/commonJS/blob/master/src/forWindow.js 代码 /** * Cre ...

  6. Python核心编程-基础2

    open() 和 file() 函数会同时存在, 完成相同的功能.一般说来, 我们建议使用 open() 来读写文件, 在您想说明您在处理文件对象时使用 file() , 例如 if instance ...

  7. 删除内容并不能删除field structure -- features_revert

    把内容删了但field structure还在, 在manage_field界面,field还在.http://drupal.stackexchange.com/questions/21501/rev ...

  8. VB6 GDI+ 入门教程[6] 图片

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[6] 图片 2009 年 6 月 19 日 15条评论 ...

  9. as的Enter_Frame与Timer

    As3中的Timer和Event.EnterFrame是有明显的区别的. Evnet.EnterFrame是定时间隔多少时间出发.如果执行时间比间隔时间长,则会间隔执行时间这么久. 举个例子: Fla ...

  10. python 练习 16

    #!/usr/bin/python # -*- coding: UTF-8 -*- import time myD = {1: 'a', 2: 'b'} for key, value in dict. ...