2014
03-23

# Line belt

In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww’s speed on AB is P and on CD is Q, he can move with the speed R on other area on the plane.
How long must he take to travel from A to D?

The first line is the case number T.
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax，Ay，Bx，By，Cx，Cy，Dx，Dy<=1000
1<=P，Q，R<=10

The first line is the case number T.
For each case, there are three lines.
The first line, four integers, the coordinates of A and B: Ax Ay Bx By.
The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.
The third line, three integers, P Q R.
0<= Ax，Ay，Bx，By，Cx，Cy，Dx，Dy<=1000
1<=P，Q，R<=10

1
0 0 0 100
100 0 100 100
2 2 1

136.60

————————————————————————————-

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct point
{
double x,y;
};
const double eps=1e-4;
double p,q,r;
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double cal_ab(point a,point b,point m)
{
point left=a,right=b;
point mid,midmid;
double ans1,ans2;
do
{
mid.x=(left.x+right.x)/2.0;
mid.y=(left.y+right.y)/2.0;
midmid.x=(left.x+mid.x)/2.0;
midmid.y=(left.y+mid.y)/2.0;
ans1=dis(mid,a)/p+dis(mid,m)/r;
ans2=dis(midmid,a)/p+dis(midmid,m)/r;
if(ans1<ans2)
left=midmid;
else
right=mid;
}while(fabs(ans1-ans2)>eps);
return ans1;
}
double cal_abcd(point a,point b,point c,point d)
{
point left=c,right=d;
point m,mm;
double ans1,ans2;
do
{
m.x=(left.x+right.x)/2.0;
m.y=(left.y+right.y)/2.0;
mm.x=(left.x+m.x)/2.0;
mm.y=(left.y+m.y)/2.0;
ans1=dis(m,d)/q+cal_ab(a,b,m);
ans2=dis(mm,d)/q+cal_ab(a,b,mm);
if(ans1<ans2)
left=mm;          //做三分题时的一句口诀:小(left)对小,大(right)对大
else
right=m;
}while(fabs(ans1-ans2)>eps);
return ans1;
}
int main()
{
int t;
point a,b,c,d;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
scanf("%lf%lf%lf",&p,&q,&r);
printf("%.2lf/n",cal_abcd(a,b,c,d));
}
return 0;
}