HDU 2300 Crashing Robots
Crashing Robots
题意
- 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态
- 这是个模拟题需要注意几点:
- 理解转变方向后移动多少米,和转动方向多少次的区别,这里后一种,在于自己审题
- crash robot 需要
区别哪一个是最先找到的
代码(自己写的比较乱)
int move[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
//1..A or B
std::map<char,int> mp={{'E',0},{'N',1},{'W',2},{'S',3}};
struct node{
int x,y;
int dir;
};//record position
int xb,yb;//x,y边界
node pos[105];//记录当前robot 位置
int ros,ins;//robots num and instruction nums
bool cr(int x1,int x2,int x){
return (x1<=x&&x<=x2)||(x2<=x&&x<=x1);
}
bool crash_robot(node b,node e,node r){
if(cr(b.x,e.x,r.x)&&cr(b.y,e.y,r.y)) return true;
else return false;
}
int check(int a, char ins,int len){
//return 1 crash robot 2 crash wall 3 OK temparily
//
node tmp=pos[a];
if(ins=='L'){
pos[a].dir=(pos[a].dir+len)%4;
}
else if(ins=='R'){
pos[a].dir=(pos[a].dir-len+400)%4;
}
//
else if(ins=='F'){
tmp.x=pos[a].x+move[pos[a].dir][0]*len;
tmp.y=pos[a].y+move[pos[a].dir][1]*len;
tmp.dir=pos[a].dir;
int near_rob=-1;
for(int j=1;j<=ros;j++){
//需要判断谁先撞上
if(j!=a){
if(crash_robot(pos[a],tmp,pos[j])){
if(near_rob==-1) near_rob=j;
else {
if(abs(pos[j].x-pos[a].x+pos[j].y-pos[a].y)<abs(pos[near_rob].x+pos[near_rob].y-pos[a].x-pos[a].y)) near_rob=j;
}
//printf("Robot %d crashes into robot %d\n",a,j);
}
}
}
pos[a]=tmp;
if(near_rob!=-1){
printf("Robot %d crashes into robot %d\n",a,near_rob);
return 1;
}
//no crash robot
//check crash wall
if(tmp.x<=0||tmp.x>=xb+1||tmp.y<=0||tmp.y>=yb+1){
printf("Robot %d crashes into the wall\n",a);
pos[a]=tmp;
return 2;
}
pos[a]=tmp;
}
return 0;
}
HDU 2300 Crashing Robots的更多相关文章
- poj2632 Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9859 Accepted: 4209 D ...
- Crashing Robots(imitate)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8124 Accepted: 3528 D ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8340 Accepted: 3607 D ...
- poj 2632 Crashing Robots
点击打开链接 Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6655 Accepted: ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- POJ2632——Crashing Robots
Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...
- POJ 2632 Crashing Robots (坑爹的模拟题)
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6599 Accepted: 2854 D ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
随机推荐
- 路飞学城Python-Day101
57-多表操作之一对多添加纪录 def add(request): # pub = Publish.objects.create(name='人民出版社', email='873245193@qq.c ...
- Css进阶练习(实现抽屉网样式布局)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- idea使用lombok
1.这玩意可以帮助我们自动实现set.get方法,实现过程有两处,只要理解了这两处,对其实际工作如何使用就非常简单了 2.第一点就是编译过程,比如使用gradle build 等编译工具进行编译时,会 ...
- 第一章 JavaScript 简介
1.1 JavaScript 的简史 JavaScript 诞生于1995年 ,后由 欧洲计算机制造商协会( ECMA,European Computer Manufacturers Associ ...
- JavaScript 原型 原型链
一. 普通对象与函数对象 JavaScript 中,万物皆对象!但对象也是有区别的.分为普通对象和函数对象,Object .Function 是 JS 自带的函数对象.下面举例说明 var o1 = ...
- 使用IO,递归打印目录树
package chengbaoDemo; import java.io.File; import java.io.IOException; public class TestIOFile { pub ...
- 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclips
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclips ...
- 【Web API系列教程】3.4 — 实战:处理数据(处理实体关系)
前言 本部分描写叙述了EF怎样载入相关实体的细节,而且怎样在你的模型类中处理环形导航属性.(本部分预备了背景知识,而这不是完毕这个教程所必须的.你也能够跳到第五节) 预载入和延迟载入 预载入和延迟载入 ...
- 学习ASP.NET MVC系列 - 还有比这更简炼的吗?把复杂的事情变简单了,贡献啊!
转自
- oracle经常使用函数(2)
1.TRIM([ { { LEADING | TRAILING | BOTH }[ trim_character ]| trim_character} FROM ]trim_source) 函数 參数 ...