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. poj2079Triangle(N点中三点组成三角形面积最大)

    链接 根据旋转卡壳的思想,找到当前边的最远点. 确定i,j找到最远的k使 cross(i,j,k)最大,那么i,j+1时只需从k+1开始找即可 . #include <iostream> ...

  2. python操作postgresql数据库

    import psycopg2 conn = psycopg2.connect(database=") cur = conn.cursor() cur.execute("CREAT ...

  3. PHP 迭代器模式

    迭代器:类继承PHP的Iterator接口,批量操作. 1. 迭代器模式,在不需要了解内部实现的前提下,遍历一个聚合对象的内部元素.2. 相比传统的编程模式,迭代器模式可以隐藏遍历元素的所需操作.接口 ...

  4. linux 静态库、共享库

    http://blog.chinaunix.net/uid-26833883-id-3219335.html http://blog.chinaunix.net/uid-23069658-id-314 ...

  5. Vbs脚本经典教材(转)

    Vbs脚本经典教材(最全的资料还是MSDN) —为什么要使用Vbs? 在Windows中,学习计算机操作也许很简单,但是很多计算机工作是重复性劳动,例如你每周也许需要对一些计算机文件进行复制.粘贴.改 ...

  6. python语法笔记(六)

    1.序列的方法     python中序列包含列表list.元组tuple.字符串str. 可以用于序列(表.元组.字符串)的内建函数: len(s) 返回: 序列中包含元素的个数 min(s) 返回 ...

  7. linux删除文件未释放空间问题处理

    linux删除文件未释放空间问题处理 或者 /根分区满了 (我的根分区是/dev/sda1,/dev/sda1满了) http://blog.csdn.net/donghustone/article/ ...

  8. js代码如何测试代码运行时间

    function add(){ //这里放要执行的代码 } //开始测试并输出 function test() { var start=new Date().getTime(); add(); var ...

  9. Java substring() 方法

    Java String类 substring() 方法返回字符串的子字符串. 语法 public String substring(int beginIndex) 或 public String su ...

  10. 日期操作类--Date类

    Date-API ava.util包提供了Date类来封装当前的日期和时间.Date类提供两个构造函数来实例化Date对象.第一个构造函数使用当前日期和时间来初始化对象. Date( ) 第二个构造函 ...