三分 例题 HDU - 3400

A - 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?

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

。。。要注意的是三等分点是 

设A1(X1,Y1),A2(X2,Y2)
三等分点为A3(X3,Y3),A4(X4,Y4)
X3=(X2+2X1)/3,Y3=(Y2+2Y1)/3
X4=(2X2+X1)/3,Y4=(2Y2+Y1)/3

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<deque>
#include<stack>
#include<queue>
#include<algorithm>
#include<math.h>
#include<deque>
#define MAX 100000+5
using namespace std;
typedef long long LL;
double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,P,Q,R;
double qwe1(double a1,double a2,double b1,double b2)
{
    return sqrt((a1-b1)*(a1-b1)+(a2-b2)*(a2-b2));
}
void qwe2(double a1,double a2,double b1,double b2,double *a,double *b)
{
    *a = ( a1*2 + b1 ) / 3.0;
    *b = ( a2*2 + b2 ) / 3.0;
}
void qwe22(double a1,double a2,double b1,double b2,double *a,double *b)
{
    *a=(a1+b1*2)/3.0;
    *b=(a2+b2*2)/3.0;
}
double Q1(double a,double b)
{
    double l1,l2,r1,r2,z1,z2,x1,x2,t,t1,t2;
    z1=l1=Cx;
    z2=l2=Cy;
    x1=r1=Dx;
    x2=r2=Dy;
    while(qwe1(z1,z2,x1,x2)>=0.000001)
    {

        qwe2(z1,z2,x1,x2,&l1,&l2);
        qwe22(z1,z2,x1,x2,&r1,&r2);
        t1=qwe1(a,b,l1,l2)/R;
        t2=qwe1(a,b,r1,r2)/R;
        if(t1+qwe1(l1,l2,Dx,Dy)/Q>t2+qwe1(r1,r2,Dx,Dy)/Q)
        {
            z1=l1;
            z2=l2;
        }
        else
        {
            x1=r1;
            x2=r2;
        }
    }

    t=qwe1(z1,z2,a,b)/R+qwe1(z1,z2,Dx,Dy)/Q;
    return t;
}
int main()
{
    double z1,z2,l1,l2,r1,r2,x1,x2,t1,t2,t;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf%lf%lf",&Ax,&Ay,&Bx,&By);
        scanf("%lf%lf%lf%lf",&Cx,&Cy,&Dx,&Dy);
        scanf("%lf%lf%lf",&P,&Q,&R);
        z1=l1=Ax;
        z2=l2=Ay;
        x1=r1=Bx;
        x2=r2=By;
        while(qwe1(z1,z2,x1,x2)>=0.0000001)
        {
            qwe2(z1,z2,x1,x2,&l1,&l2);
            qwe22(z1,z2,x1,x2,&r1,&r2);
            t1=Q1(l1,l2);
            t2=Q1(r1,r2);
            if(t1+qwe1(l1,l2,Ax,Ay)/P>t2+qwe1(r1,r2,Ax,Ay)/P)
            {
                z1=l1;
                z2=l2;
            }
            else
            {
                x1=r1;
                x2=r2;
            }
        }
        printf("%.2lf\n",qwe1(z1,z2,Ax,Ay)/P+Q1(z1,z2));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41886199/article/details/81116088
今日推荐