Hurry Up | ||
Accepted : 66 | Submit : 264 | |
Time Limit : 1000 MS | Memory Limit : 65536 KB |
Problem DescriptionGG is some what afraid of his MM. Once his MM asks, he will always try his best to rush to their home.
InputMultiple test cases. First line, an integer T ( 1 ≤ T ≤ 2000 ), indicating the number of test cases.
OuputFor 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 Input2 1 1 2 2 1 2 1 1 2 2 1 7 Sample Output1.41 1.32 SourceXTU OnlineJudge |
#include<cstdio>
#include<cmath>
#define min(x,y) (x < y ? x : y)
#define f(dt) (sqrt( (x_1 - dt)*(x_1 - dt) + y_1 * y_1) /vr + sqrt( (x_2 - dt) * (x_2 - dt) + y_2 * y_2)/vt)
double x_1,y_1,x_2,y_2,vr,vt;
#define EPS 1e-4
double slove()
{
double l = x_1, r = x_2, lm, rm, flm, frm;
double ans;
ans = min( f(l), f(r));
while(fabs(r - l) > EPS)
{
lm = l + (r - l)/3;
rm = l + 2 *(r - l)/3;
flm = f(lm);
frm = f(rm);
if(flm > frm) l = lm;
else r = rm;
}
ans = min(ans, f(r));
return ans;
}
int main ()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf", &x_1,&y_1,&x_2,&y_2,&vr,&vt);
double t1,t2;
t1 = sqrt((x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1)) / vr;
t2 = slove();
double ans = min(t1,t2);
printf("%.2lf\n", ans);
}
return 0;
}