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> ...
随机推荐
- HDU5807分段dp
DAG图. [题意] n(50)个城市m(c(n,2))条单向边(x,y),保证x<y 对于三个点(x,y,z)如果abs(w[x]-w[y])<=K && abs(w[x ...
- js之oop <一> 创建对象,构造器(class)
js中除了基本类型,就是对象.可以说在js中处处皆对象. 由于js是弱语言,在编写的过程中很容易混淆 object 和 class 也就是对象和构造器. object(对象):一般对象都由var关键字 ...
- Java Performance - 优化和分析Garbage Collection/垃圾收集
随着硬件的不断提升,Java Heap 越来越大,合理的垃圾收集调优变得愈发重要.下面介绍一些最佳实践: 注意: 下面不涉及 IBM AIX Java. 同时不介绍原理,仅仅是建议以及初始配置/最佳实 ...
- C/C++中堆与栈
本文介绍C/C++中堆,栈及静态数据区. 五大内存分区 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区.下面分别来介绍: 栈,就是那些由编译器在需要的时候分 ...
- 使用Visual Studio制作安装包
目 录 第1章 合并模块 3 1.1 SystemDll 3 1.1.1 收集文件 3 1.1.2 新建项目 4 1.1.3 增加自定义文件夹 4 1.1.4 设置部署位 ...
- 可持久化Trie & 可持久化平衡树 专题练习
[xsy1629]可持久化序列 - 可持久化平衡树 http://www.cnblogs.com/Sdchr/p/6258827.html [bzoj4260]REBXOR - Trie 事实上只是一 ...
- 【bzoj1059】矩形游戏
题意 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏--矩阵游戏.矩阵游戏在一个N*N黑白方阵进行(如同国际象棋一般,只是颜色是随意的).每次可以对该矩阵进行两种操作:行交换操作 ...
- 【转】commons-lang.jar包简介
转自:http://zhidao.baidu.com/share/71b48e6b3e1b1dc73fe705604b9c7584.html 1.下载jar包 包官方下载地址:http://commo ...
- 从Oracle迁移到Mysql之前必须知道的50件事
1. 对子查询的优化表现不佳. 2. 对复杂查询的处理较弱 3. 查询优化器不够成熟 4. 性能优化工具与度量信息不足 5. 审计功能相对较弱 6. 安全功能不成熟,甚至可以说很粗糙.没有用户组与角色 ...
- 如何处理PHP和MYSQL的并发以及优化
sql优化,数据缓存和页面静态化首先各种优化程序逻辑优化数据库优化硬件横向扩展数据hash.服务器提升性能.表hash.出钱找oraclec出解决方案页面静态化:Php页面静态化有两种,第一,php模 ...