1006 Line belt

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.
How long must he take to travel from A to D?
 

Input
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
 

Output
The minimum time to travel from A to D, round to two decimals.
 

Sample Input

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

Sample Output

136.60
 

Author
lxhgww&&momodi



  1. #include  
  2. #include  
  3. #include  
  4. #define eps 1e-15  
  5. using namespace std;  
  6. struct point  
  7. {  
  8.     double x,y;  
  9. };  
  10. point A,B,C,D;  
  11. double P,Q,R;  
  12. int sgn(double a)  
  13. {  
  14.     return (a>eps)-(a<-eps);  
  15. }  
  16. double dist(point a,point b)  
  17. {  
  18.     return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));  
  19. }  
  20. double calcu_lin(point a,point b,point c,point d)  
  21. {  
  22.     return dist(a,b)/P+dist(b,c)/R+dist(c,d)/Q ;  
  23. }  
  24. point MID(point a,point b)  
  25. {  
  26.     point c;  
  27.     c.x=(a.x+b.x)*0.5;  
  28.     c.y=(a.y+b.y)*0.5;  
  29.     return c;  
  30. }  
  31. double sanfen1(point a,point b,point c,point d,point &mid)  
  32. {  
  33.    point mid1,midmid;  
  34.     point l,rr;l=c;rr=d;  
  35.     double t1,t2;  
  36.    do  
  37.    {  
  38.      mid1=MID(l,rr);  
  39.      midmid=MID(mid1,rr);  
  40.      t1=calcu_lin(a,b,mid1,d);  
  41.      t2=calcu_lin(a,b,midmid,d);  
  42.      if(t1
  43.      rr=midmid;  
  44.      else  
  45.      l=mid1;  
  46.    }  
  47.    while(sgn(t1-t2)!=0);  
  48.    mid=mid1;  
  49.    return  t1;  
  50. }  
  51. double sanfen2(point d,point c,point b,point a,point &mid)  
  52. {  
  53.    point mid1,midmid;  
  54.     point l,rr;l=a;rr=b;  
  55.     double t1,t2;  
  56.    do  
  57.    {  
  58.      mid1=MID(l,rr);  
  59.      midmid=MID(mid1,rr);  
  60.      t1=calcu_lin(a,mid1,c,d);  
  61.      t2=calcu_lin(a,midmid,c,d);  
  62.      if(t1
  63.      rr=midmid;  
  64.      else  
  65.      l=mid1;  
  66.    }  
  67.    while(sgn(t1-t2)!=0);  
  68.    mid=mid1;  
  69.    return  t1;  
  70. }  
  71. void work()  
  72. {  
  73.     double t1,t2;point mid1,mid2;  
  74.     mid1.x=B.x;mid1.y=B.y;  
  75.     do  
  76.     {  
  77.         //printf("okok\n");  
  78.       t1=sanfen1(A,mid1,C,D,mid2);  
  79.       t2=sanfen2(D,mid2,B,A,mid1);  
  80.     }  
  81.     while(sgn(t1-t2)!=0);  
  82.     printf("%.2lf\n",t1);  
  83. }  
  84. int main()  
  85. {  
  86.     int t;  
  87.     double ff;  
  88.     scanf("%d",&t);  
  89.      while(t--)  
  90.     {  
  91.         scanf("%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y);  
  92.         scanf("%lf%lf%lf%lf",&C.x,&C.y,&D.x,&D.y);  
  93.         scanf("%lf%lf%lf",&P,&Q,&R);  
  94.           work();  
  95.   
  96.   
  97.     }  
  98.   
  99.     return 0;  


你可能感兴趣的:(1006 Line belt)