当前位置: 代码迷 >> PB >> HDOJ 标题3158 PropBot(DFS)
  详细解决方案

HDOJ 标题3158 PropBot(DFS)

热度:491   发布时间:2016-04-29 05:18:38.0
HDOJ 题目3158 PropBot(DFS)

PropBot

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 190    Accepted Submission(s): 60


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.
 

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.
 

Sample Input
224 5.0 5.09 7.0 17.0
 

Sample Output
0.5025250.100505
 

Source
2008 ACM-ICPC Pacific Northwest Region
 

Recommend
chenrui   |   We have carefully selected several similar problems for you:  3149 3157 3156 3155 3154 
 
ac代码
#include<stdio.h>#include<string.h>#include<math.h>double dd=sqrt(2.0)/2*10,d;int time;double ex,ey;double dis(double x1,double y1,double x2,double y2){	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}void dfs(double x,double y,int dir,int tim){	double ds=dis(x,y,ex,ey);	dir%=8;	if(ds<d)	{		d=ds;	}	if(tim>=time||(ds-10*(time-tim)>d))		return;	if(dir==0)	{		dfs(x+10,y,dir,tim+1);	}	else if(dir==1)	{		dfs(x+dd,y-dd,dir,tim+1);	}	else if(dir==2)	{		dfs(x,y-10,dir,tim+1);	}	else if(dir==3)	{		dfs(x-dd,y-dd,dir,tim+1);	}	else if(dir==4)	{		dfs(x-10,y,dir,tim+1);	}	else if(dir==5)	{		dfs(x-dd,y+dd,dir,tim+1);	}	else if(dir==6)	{		dfs(x,y+10,dir,tim+1);	}	else if(dir==7)	{		dfs(x+dd,y+dd,dir,tim+1);	}	dfs(x,y,dir+1,tim+1);}int main(){	int t;	scanf("%d",&t);	while(t--)	{		scanf("%d%lf%lf",&time,&ex,&ey);		d=dis(0,0,ex,ey);		dfs(0,0,0,0);		printf("%.6lf\n",d);	}}