1 0 0 0 100 100 0 100 100 2 2 1Sample Output
136.60
#include
#include
#include
using namespace std;
const double eps=1e-8;
struct Point
{
double x,y;
}a,b,c,d,bb,dd;
double ab,cd,p,q,r;
double dis(Point u,Point v)
{
return sqrt(eps+(u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));
}
double work(double t)
{
dd.x=d.x+(c.x-d.x)/cd*t*q;
dd.y=d.y+(c.y-d.y)/cd*t*q;
return t+dis(bb,dd)/r;
}
double solve(double t)
{
bb.x=a.x+(b.x-a.x)/ab*t*p;
bb.y=a.y+(b.y-a.y)/ab*t*p;
double l=0,h=cd/q,mid1,mid2;
while(h-l>eps)
{
mid1=(l*2+h)/3;
mid2=(h*2+l)/3;
if(work(mid1)
else
l=mid1;
}
return t+work(l);
}
int main()
{
int t;
cin>>t;
while(t--)
{
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
scanf("%lf%lf%lf",&p,&q,&r);
ab=dis(a,b);
cd=dis(c,d);
double l=0,h=ab/p,mid1,mid2;
while(h-l>eps)
{
mid1=(l*2+h)/3;
mid2=(h*2+l)/3;
if(solve(mid1)
else
l=mid1;
}
printf("%.2f\n",solve(mid1));
}
return 0;
}
这个是正确代码,但是如果dis哪里不加eps就是wa,我也是懵啊。哎西吧!