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.<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



  1. #include<iostream>  
  2. #include<cstdio>  
  3. #include<cmath>  
  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<t2)  
  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<t2)  
  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;  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值