HDU 3158 PropBot(DFS)
来源:互联网 发布:c语言32个关键字的意思 编辑:程序博客网 时间:2024/05/22 16:05
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3158
Problem Description
You have been selected to write the navigation module for PropBot. Unfortunately, the mechanical engineers have not provided a lot of flexibility in movement; indeed, the PropBot can only make two distinct movements. It can either move 10 cm forward, or turn towards the right by 45 degrees. Each of these individual movements takes one second of time.
Input
Your module has two inputs: the Cartesian coordinates of a point on the plane that the PropBot wants to get as close to as possible, and the maximum number of seconds that can be used to do this. At the beginning of the navigation, the robot is located at the origin, pointed in the +x direction.
The number of seconds will be an integer between 0 and 24, inclusive. Both the x and y coordinates of the desired destination point will be a real number between -100 and 100, inclusive.
The first entry in the input file will be the number of test cases, t (0 < t <= 100). Following this line will be t lines, with each line containing three entries separated by spaces. The first entry will be the number of seconds PropBot has to get close to the point. The second entry is the x-coordinate of the point, and the third entry is the y-coordinate of the point.
The number of seconds will be an integer between 0 and 24, inclusive. Both the x and y coordinates of the desired destination point will be a real number between -100 and 100, inclusive.
The first entry in the input file will be the number of test cases, t (0 < t <= 100). Following this line will be t lines, with each line containing three entries separated by spaces. The first entry will be the number of seconds PropBot has to get close to the point. The second entry is the x-coordinate of the point, and the third entry is the y-coordinate of the point.
Output
Your program must return the distance between the goal point and the closest point the robot can get to within the given time.
Your result should include at least one digit to the left of the decimal point, and exactly six digits to the right of the decimal point. To eliminate the chance of round off error affecting the results, we have constructed the test data so the seventh digit to the right of the decimal point of the true result is never a 4 or a 5.
Your result should include at least one digit to the left of the decimal point, and exactly six digits to the right of the decimal point. To eliminate the chance of round off error affecting the results, we have constructed the test data so the seventh digit to the right of the decimal point of the true result is never a 4 or a 5.
Sample Input
224 5.0 5.09 7.0 17.0
Sample Output
0.5025250.100505
Source
2008 ACM-ICPC Pacific Northwest Region
题意:
每次有两个操作:
1、直线距离走10cm;
2、向右转45°;
每一个操作耗时为一秒。问在给定的时间内,能走到的离目标点最近的距离?
PS:
DFS每一步的每个方向,记录出现的最短距离;
代码如下:
#include <cstdio>#include <cstring>#include <cmath>using namespace std;const double dd = sqrt(2.0)/2*10;int ti;double x,y;double d;double dis(double x1, double y1, double x2, double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}void dfs(double x1,double y1,int dir,int tt){ double aa; dir %= 8; aa=dis(x1,y1,x,y); if(aa < d) { d = aa; } if(tt==ti ||(aa-10*(ti-tt)>d))//如果剩下的步数就算走直线都比当前的d大就不用往下搜了 { return ; } if(dir == 0)//沿+x走10cm { dfs(x1+10,y1,dir,tt+1); } else if(dir == 1)//沿+x偏-y为45°方向走10cm { dfs(x1+dd,y1-dd,dir,tt+1); } else if(dir == 2)//沿-y走10cm { dfs(x1,y1-10,dir,tt+1); } else if(dir == 3)//沿-y偏-x为45°方向走10cm { dfs(x1-dd,y1-dd,dir,tt+1); } else if(dir == 4)//沿-x走10cm { dfs(x1-10,y1,dir,tt+1); } else if(dir == 5)//沿-x偏+y为45°方向走10cm { dfs(x1-dd,y1+dd,dir,tt+1); } else if(dir == 6)//沿+y走10cm { dfs(x1,y1+10,dir,tt+1); } else if(dir == 7)//沿+y偏+x为45°方向走10cm { dfs(x1+dd,y1+dd,dir,tt+1); } dfs(x1,y1,dir+1,tt+1);}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%lf%lf",&ti,&x,&y); d = dis(0,0,x,y); dfs(0,0,0,0); printf("%.6lf\n",d); } return 0;}/*224 5.0 5.09 7.0 17.059 7.0 17.0*/
2 0
- HDU 3158 PropBot(DFS)
- HDU 3158--PropBot【DFS】
- HDOJ 题目3158 PropBot(DFS)
- 【hdu】Zipper (dfs)
- hdu 2181 (dfs)
- hdu 1241 (dfs)
- hdu 1016 (DFS)
- hdu 1045 (DFS)
- hdu 2612(dfs)
- hdu 2614(dfs)
- hdu 2610 (dfs)
- hdu~1312(dfs)
- HDU-1035(dfs)
- HDU 5495(dfs)
- HDU 2181(DFS)
- hdu 5676(dfs)
- HDU 1241(DFS)
- HDU-1010(DFS)
- 链表排序的两种实现方法
- VRPN学习笔记(二) 配置server和编写client
- TRIZ系列-创新原理-2-抽取原理
- 从ClassPathXmlApplicationContext中看spring在web中如何运行
- HDOJ 1022 Train Problem I
- HDU 3158 PropBot(DFS)
- 数据结构之栈的练习
- Spring3 注解 设置某控制器的统一的的访问路径
- 黑马程序员——面向对象6:关于静态
- hbase总结(二)-hbase安装
- 3D 打印
- OJ2017题、2018题
- bzoj3527: [Zjoi2014]力
- HDOJ 1241 Oil Deposits