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 ...
随机推荐
- MooFest 树状数组 + 前缀和
比较友好的数据结构题 建议读者好好思考思考--. 可以分析出与前缀和的关系, 之后就愉快的套起树状数组辣 #include <cstdio> #include<queue> # ...
- windows系统下jenkins环境搭建与基本使用
一. windows 系统下搭建jenkins环境 1.1 jenkins环境搭建和构建job流程图 1.2 安装jdk JDK下载地址: http://www.oracle.com/technet ...
- Vue学习之路第十三篇:v-for指令
v-for指令,看名字想必大家也能猜到其作用,没错,就是用来迭代.遍历的. 1.简单数组的遍历 <body> <divi id="app"> <spa ...
- Connection refused (SQL: select * from information_s chema.tables where table_schema = apidemo and table_name = migrations)
LARAVEL 执行: $ php artisan migrate 报错 ,把 .env文件里的 DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306 换成 ...
- 区分JAVA创建线程的几种方法
1. start()和run() 通过调用Thread类的start()方法来启动一个线程,这时此线程是处于就绪状态,并没有运行.然后 通过此Thread类调用方法run()来完成其运行操 ...
- Jquery Math ceil()、floor()、round()比较与用法
Math.ceil():向上取值 如:Math.ceil(2.1) -- 结果为 3 Math.ceil(-2.1) -- 结果为-2 结论:正入 负舍 Math.floor(): 先下取值 入 ...
- yiii 数据库备份导出
应用场景 数据对于网站来说 是非常重要的 一般 cms 后台 都有 数据备份功能.使用Yii 的第三方拓展 可以快速开发. spanjeta/yii2-backup spanjeta/yii2-bac ...
- 洛谷 U6850 手机密码
U6850 手机密码 题目背景 小明的手机上设了一个由四个数字组成的密码,但是小明自己的记性不好,但又不想把密码直接记在纸上,于是便想了一个方法. 题目描述 小明有四行数字,每行数字都有n[i](&l ...
- ORM进阶之Hibernate中对象的三大状态解析
ORM进阶之 ORM简单介绍 ORM进阶之Hibernate简单介绍及框架搭 ORM进阶之Hibernate的三大对象 ORM进阶之Hibernate中对象的三大状态解析 在Hibernatea中每一 ...
- css sprite的实现
css sprite 为什么使用css sprite? 网页上的非常多静态小图片在载入时须要大量http请求,添加了响应时间.(哈哈.雅虎34条优化法则的第一条啊) css的background-po ...