Problem Description
GG is some what afraid of his MM. Once his MM asks, he will always try his best to rush to their home.
Obvious, he can run home in straight line directly. Alternatively, he can run to the main road and call the taxi.
You can assume there is only one main road on the x-axis, with unlimited length.
Given the initial location of GG and his destination, please help to ask the minimize time to get home.
GG will always run at the fixed speed of vr, and the taxi can move at the fixed speed of vt
You can also assume that, only GG reach the main road, he can catch the taxi immediately. And the taxi will go towards home ( not necessay along the road ).
Bisides, GG can run arbitrary length, and pay arbitrarily for the taxi.
P.S. MM: abbr. Ma Ma
Input
Multiple test cases. First line, an integer T ( 1 ≤ T ≤ 2000 ), indicating the number of test cases.
For each test cases, there are 6 integers x1, y1, x2, y2, vr, vt in a line.
( -1000 <= x1, y1, x2, y2 <= 1000, 1 <= vr < vt <= 1000 )
(x1, y1) : the initial location of GG
(x2, y2) : the destination location of GG
vr: GG's run speed
vt: taxi's speed
Ouput
For each test case, output a real number with 2 digits after the arithmetic point. It is the shorest time for GG to reach home.
Sample Input
2 1 1 2 2 1 2 1 1 2 2 1 7
Sample Output
1.41 1.32
1 #include <iostream> 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #define e 1e-10 6 using namespace std; 7 8 double x1,y11,x2,y22,vr,vt; 9 10 double cal(double x) 11 { 12 return sqrt((x1-x)*(x1-x)+y11*y11)/vr + sqrt((x2-x)*(x2-x)+y22*y22)/vt; 13 } 14 double solve() 15 { 16 double mid ,midmid; 17 if(x1>x2) swap(x1,x2); 18 double l=x1,r=x2; 19 while(l+e<r) 20 { 21 mid = (l+r)/2; 22 midmid = (mid+r)/2; 23 double midval,midmidval; 24 midval = cal(mid); 25 midmidval = cal(midmid); 26 if(midval < midmidval) 27 { 28 r=midmid; 29 } 30 else l=mid; 31 } 32 return cal(l); 33 } 34 int main() 35 { 36 int t; 37 scanf("%d",&t); 38 while(t--) 39 { 40 scanf("%lf %lf %lf %lf %lf %lf",&x1,&y11,&x2,&y22,&vr,&vt); 41 double ans1,ans; 42 ans=sqrt((x1-x2)*(x1-x2)+(y11-y22)*(y11-y22))/vr; 43 ans1=solve(); 44 printf("%.2lf\n",ans<ans1?ans:ans1); 45 } 46 return 0; 47 }