Line belt HDU - 3400 三分

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

平面上两条直线AB,CD,动点从A出发,在某点离开AB前往CD某点,再到达D点,各直线和平面上移动速度不同,求最少时间。
从AB哪点出发,和到达CD哪点都是需要查找的对象,所以要两次三分,先三分查找第一个点,再在该情况下找最优的第二个点。

#include <stdio.h>
#include <math.h>
int T,i,j;
double s,p,q,r;
struct node{
    double x,y;
    node(int xx=0,int yy=0):x(xx),y(yy){}
}a,b,c,d;

double dis(node aa,node bb){
    double re=sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y));
    return re;
}

double sf2(node n){
    double t1,t2;
    node low(c.x,c.y);
    node high(d.x,d.y);
    node m1,m2;
    do{
        m1.x=(low.x+high.x)/2;
        m1.y=(low.y+high.y)/2;
        m2.x=(low.x+m1.x)/2;
        m2.y=(low.y+m1.y)/2;
        t1=dis(m1,d)/q+dis(n,m1)/r;
        t2=dis(m2,d)/q+dis(n,m2)/r;
        if(t1<t2){
            low.x=m2.x;
            low.y=m2.y;
        }else{
            high.x=m1.x;
            high.y=m1.y;
        }
    }while(dis(low,high)>1e-8);
    return t1;
}

double sf1(){
    double t1,t2;
    node low(a.x,a.y);
    node high(b.x,b.y);
    node m1,m2;
    do{
        m1.x=(low.x+high.x)/2;
        m1.y=(low.y+high.y)/2;
        m2.x=(low.x+m1.x)/2;
        m2.y=(low.y+m1.y)/2;
        t1=sf2(m1)+dis(m1,a)/p;
        t2=sf2(m2)+dis(m2,a)/p;
        if(t1<t2){
            low.x=m2.x;
            low.y=m2.y;
        }else{
            high.x=m1.x;
            high.y=m1.y;
        }
    }while(dis(low,high)>1e-8);
    return t1;
}


int main()
{

    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);
        s=sf1();
        printf("%.2lf\n",s);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值