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 ...
随机推荐
- GNU/Linux分支图
- Python智能提示--提示对象内涵成员
1. demo展示 2. 提示效果
- 00074_Array类
1.Array类的概述 此类包含用来操作数组(比如排序和搜索)的各种方法.需要注意,如果指定数组引用为 null,则访问此类中的方法都会抛出空指针异常NullPointerException. 2.常 ...
- 【codeforces 724E】Goods transportation
[题目链接]:http://codeforces.com/problemset/problem/724/E [题意] 有n个城市; 这个些城市每个城市有pi单位的物品; 然后已知每个城市能卖掉si单位 ...
- linux下sort对中文排序
http://blog.csdn.net/luoleicn/article/details/6162358 设置: export LC_ALL=C;
- POJ 1950
直接DFS,因为实在没想到什么剪枝了... 注意一点是,10.11使用的是1011哦 #include <iostream> #include <cstdio> #includ ...
- .NET 图片解密为BASE64
#region 图片加密 /// <summary> /// 加密本地文件 /// </summary> /// <param name="inputname& ...
- 王立平--Object-c
object-c通常写作objective-c或者obj-c,是依据C语言所衍生出来的语言.继承了C语言的特性,是扩充C的面向对象编程语言. 它主要使用于MacOSX和GNUstep这两个使用Open ...
- spark 随机森林算法案例实战
随机森林算法 由多个决策树构成的森林,算法分类结果由这些决策树投票得到,决策树在生成的过程当中分别在行方向和列方向上添加随机过程,行方向上构建决策树时采用放回抽样(bootstraping)得到训练数 ...
- DB-MySQL:MySQL 序列使用
ylbtech-DB-MySQL:MySQL 序列使用 1.返回顶部 1. MySQL 序列使用 MySQL 序列是一组整数:1, 2, 3, ...,由于一张数据表只能有一个字段自增主键, 如果你想 ...