POJ 2632 Crashing Robots 模拟 难度:0
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的更多相关文章
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- POJ 2632 Crashing Robots(较为繁琐的模拟)
题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- poj 2632 Crashing Robots_模拟
做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a. 题意:给你机器人怎走的路线,碰撞就输出 #include <cstdlib> #include <iostream> ...
随机推荐
- create table xxx as select 与 create table xxx like
create table xxx ) | NO | PRI | NULL | auto_increment | | Name | varchar() | NO | ...
- 关于协程的学习 & 线程栈默认10M
先看的这篇文章:http://blog.csdn.net/qq910894904/article/details/41699541 以nginx为代表的事件驱动的异步server正在横扫天下,那么事件 ...
- 进程 & 线程相关知识
不管Java,C++都有进程.线程相关的内容.在这里统一整理吧. Python的线程,其实是伪线程,不能真正的并发.下面也有讲. 线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序 ...
- CodeForces 185A 快速幂
一开始找矩阵快速幂的题来做时就看到了这题,题意就是让你求出如图所示的第n个三角形中指向向上的小三角形个数.从图中已经很容易看出递推关系了,我们以f[n]表示第n个大三角形中upward的小三角形个数, ...
- Spring Bean配置默认为单实例 pring Bean生命周期
Bean默认的是单例的. 如果不想单例需要如下配置:<bean id="user" class="..." scope="singleton&q ...
- 提高php开发效率的9大代码片段
在网站开发中,我们都期望能高效快速的进行程序开发,如果有能直接使用的代码片段,提高开发效率,那将是极好的.php开发福利来了,今天小编就将为大家分享9大超实用的.可节省大量开发时间的php代码片段. ...
- Java客户端通过Http发送POST请求上传文件到web服务器
http://www.cnblogs.com/WilliamJiang/archive/2012/04/29/2475883.html 1.朋友的一个需求,让我给他实现,需求是这样的,需要用ASP.n ...
- 【bzoj1029】道路抢修
[bzoj1029]建筑抢修 传送门 http://www.lydsy.com/JudgeOnline/problem.php?id=1029 分析 http://blog.csdn.net/popo ...
- 核心Javascript学习
1. 引言: 1.1. 网页三要素: l HTML(内容) l CSS(外观) l Javascript(行为) 1.2. OOP的相关概念 1). 对象,方法和属性 l 对象就是指"事物 ...
- static与C#中的static
Static 1.静态方法与非静态方法 a.静态方法的调用类.静态方法名([参数列表]) 非静态方法的调用类 对象 = new 类的构造函数([参数列表])对象.非静态方法名([参数列表]) 静态方法 ...