Problem Description
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.<br>How long must he take to travel from A to D?
Input
The first line is the case number T.<br>For each case, there are three lines.<br>The first line, four integers, the coordinates of A and B: Ax Ay Bx By.<br>The second line , four integers, the coordinates of C and D:Cx Cy Dx Dy.<br>The third line, three integers, P Q R.<br>0<= Ax,Ay,Bx,By,Cx,Cy,Dx,Dy<=1000<br>1<=P,Q,R<=10
Output
The minimum time to travel from A to D, round to two decimals.
Sample Input
1<br>0 0 0 100<br>100 0 100 100<br>2 2 1
Sample Output
136.60
Author
lxhgww&&momodi
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #define eps 1e-15
- using namespace std;
- struct point
- {
- double x,y;
- };
- point A,B,C,D;
- double P,Q,R;
- int sgn(double a)
- {
- return (a>eps)-(a<-eps);
- }
- double dist(point a,point b)
- {
- return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
- }
- double calcu_lin(point a,point b,point c,point d)
- {
- return dist(a,b)/P+dist(b,c)/R+dist(c,d)/Q ;
- }
- point MID(point a,point b)
- {
- point c;
- c.x=(a.x+b.x)*0.5;
- c.y=(a.y+b.y)*0.5;
- return c;
- }
- double sanfen1(point a,point b,point c,point d,point &mid)
- {
- point mid1,midmid;
- point l,rr;l=c;rr=d;
- double t1,t2;
- do
- {
- mid1=MID(l,rr);
- midmid=MID(mid1,rr);
- t1=calcu_lin(a,b,mid1,d);
- t2=calcu_lin(a,b,midmid,d);
- if(t1<t2)
- rr=midmid;
- else
- l=mid1;
- }
- while(sgn(t1-t2)!=0);
- mid=mid1;
- return t1;
- }
- double sanfen2(point d,point c,point b,point a,point &mid)
- {
- point mid1,midmid;
- point l,rr;l=a;rr=b;
- double t1,t2;
- do
- {
- mid1=MID(l,rr);
- midmid=MID(mid1,rr);
- t1=calcu_lin(a,mid1,c,d);
- t2=calcu_lin(a,midmid,c,d);
- if(t1<t2)
- rr=midmid;
- else
- l=mid1;
- }
- while(sgn(t1-t2)!=0);
- mid=mid1;
- return t1;
- }
- void work()
- {
- double t1,t2;point mid1,mid2;
- mid1.x=B.x;mid1.y=B.y;
- do
- {
- //printf("okok\n");
- t1=sanfen1(A,mid1,C,D,mid2);
- t2=sanfen2(D,mid2,B,A,mid1);
- }
- while(sgn(t1-t2)!=0);
- printf("%.2lf\n",t1);
- }
- int main()
- {
- int t;
- double ff;
- scanf("%d",&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);
- work();
- }
- return 0;
- }