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
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
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.
2 1 1 2 2 1 2 1 1 2 2 1 7
1.41 1.32
XTU OnlineJudge
三分枚举答案。。。
坐的士的话,有两条路,一条是步行到X轴的时间,一段是X轴到家的时间,并且由于从左到有枚举X点的话,随着两段路长短的变化,时间也是递增的,所以可以进行三分
#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; double x1,x2,yy1,yy2,vr,vt; double dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double fun(double x) { return dis(x1,yy1,x,0)/vr+dis(x2,yy2,x,0)/vt; } int main() { int t; double t1,t2; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%lf%lf%lf",&x1,&yy1,&x2,&yy2,&vr,&vt); if(x1>x2) swap(x1,x2); t1 = dis(x1,yy1,x2,yy2)/vr; double l = x1,r = x2; while(r-l>1e-8) { double mid1 = (l+r)/2; double mid2 = (mid1+r)/2; if(fun(mid1)<fun(mid2)) r = mid2; else l = mid1; } printf("%.2f\n",t1<fun(l)?t1:fun(l)); } return 0; }
XTU1175:Hurry Up(三分),布布扣,bubuko.com
原文:http://blog.csdn.net/libin56842/article/details/25986227