Hurry Up | ||
Accepted : 112 | Submit : 393 | |
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
#include
#include
#include
using namespace std;
const double EPS=1e-9;
double x1, x2, yy, y2, vr, vc;
double f(double x)
{
return sqrt(yy*yy + (x1 - x)*(x1 - x)) / vr + sqrt(y2*y2 + (x2 - x)*(x2 - x))/vc;
}
double ternary_search(double L, double R)
{
double mid1, mid2;
if (L > R)
swap(L, R);
while (R - L > EPS)
{
mid1 = L + (R - L) / 3;
mid2 = R - (R - L) / 3;
if (f(mid1) > f(mid2))
L = mid1;
else
R = mid2;
}
return f((L + R)*0.5);
}
int main(void)
{
int t;
cin >> t;
while (t--)
{
cin>>x1>>yy>>x2>>y2>>vr>>vc;
double ans = sqrt((x1 - x2)*(x1 - x2) + (yy - y2)*(yy - y2))/vr;
ans = min(ans, ternary_search(x1, x2));
printf("%.2lf\n", ans);
}
return 0;
}
/*
2
1 1 2 2 1 2
1 1 2 2 1 7
*/