搜索(三分):HDU 3400 Line belt
Posted 既然选择了远方,便只顾风雨兼程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搜索(三分):HDU 3400 Line belt相关的知识,希望对你有一定的参考价值。
Line belt
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3531 Accepted Submission(s): 1364
Problem Description
In
a two-dimensional plane there are two line belts, there are two
segments AB and CD, lxhgww‘s speed on AB is P and on CD is Q, he can
move with the speed R on other area on the plane.
How long must he take to travel from A to D?
How long must he take to travel from A to D?
Input
The first line is the case number T.
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000
1<=P,Q,R<=10
Output
The minimum time to travel from A to D, round to two decimals.
Sample Input
1
0 0 0 100
100 0 100 100
2 2 1
Sample Output
136.60
1 //rp++ 2 //#include <bits/stdc++.h> 3 4 #include <iostream> 5 #include <cstring> 6 #include <cstdio> 7 #include <cmath> 8 9 using namespace std; 10 11 double eps=1e-8; 12 13 double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,P,Q,R; 14 15 double DIS(double x1,double y1,double x2,double y2) 16 { 17 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 18 } 19 20 21 double Get_Time(double p1,double p2) 22 { 23 return DIS(Ax,Ay,Ax+p1*(Bx-Ax),Ay+p1*(By-Ay))*1.0/P+DIS(Dx,Dy,Dx+p2*(Cx-Dx),Dy+p2*(Cy-Dy))*1.0/Q+ 24 DIS(Bx+(1.0-p1)*(Ax-Bx),By+(1.0-p1)*(Ay-By),Cx+(1.0-p2)*(Dx-Cx),Cy+(1.0-p2)*(Dy-Cy))*1.0/R; 25 } 26 27 double Get_MIN(double pos) 28 { 29 double L=0.0,R=1.0,x,y,ret; 30 while(R-L>=eps) 31 { 32 x=(R+2*L)/3.0; 33 y=(2*R+L)/3.0; 34 35 x=Get_Time(pos,x); 36 y=Get_Time(pos,y); 37 38 39 if(x-y>=eps)L=(R+2*L)/3.0; 40 else R=(2*R+L)/3.0; 41 42 ret=min(x,y); 43 } 44 return ret; 45 } 46 47 double Solve() 48 { 49 double L=0.0,R=1.0,x,y,ret; 50 while(R-L>=eps) 51 { 52 x=(2*L+R)/3.0; 53 y=(L+2*R)/3.0; 54 55 x=Get_MIN(x); 56 y=Get_MIN(y); 57 58 59 if(x-y>=eps)L=(2*L+R)/3.0; 60 else R=(L+2*R)/3.0; 61 62 ret=min(x,y); 63 } 64 return ret; 65 } 66 67 int main() 68 { 69 int T; 70 scanf("%d",&T); 71 while(T--) 72 { 73 scanf("%lf%lf%lf%lf",&Ax,&Ay,&Bx,&By); 74 scanf("%lf%lf%lf%lf",&Cx,&Cy,&Dx,&Dy); 75 scanf("%lf%lf%lf",&P,&Q,&R); 76 77 printf("%.2lf\n",Solve()); 78 } 79 return 0; 80 }
以上是关于搜索(三分):HDU 3400 Line belt的主要内容,如果未能解决你的问题,请参考以下文章