您的位置:首页 > 编程语言

2016SDAU编程练习二1006

2016-04-16 14:02 302 查看
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

 

Source

HDOJ Monthly Contest – 2010.05.01
 

题意:给出两条传送带的起点到末端的坐标,其中ab为p的速度,cd为q的速度 其他地方为r的速度,求a到d点的最短时间

思路:三分法,就是给了两条线段,每条中必定有一点,连接后时间最短

感想:这个就比较复杂一点了

AC代码

#include <cstdio>

#include<iostream>

#include<stdio.h>

#include<vector>

#include<algorithm>

#include<numeric>

#include<math.h>

#include<string.h>

#include<map>

#include<set>

#include<vector>

#include<iomanip>

using namespace std;

double p,q,R;

struct point

{

    double x;

    double y;

    point operator / (const point &others)

    {

        point tt;

        tt.x=(this->x+others.x)/2;

        tt.y=(this->y+others.y)/2;

        return tt;

    }

};

double length (point a,point b)

{

    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

}

double find ( point c,point d,point mid )

{

    point l,r,mid1,mid2;

    double t1,t2;

    l=c;r=d;

    do

    {

        mid1=(r/l);

        mid2=(r/mid1);

        t1=length(mid1,d)/q+length(mid1,mid)/R;

        t2=length(mid2,d)/q+length(mid2,mid)/R;

        if(t1>t2)

            l=mid1;

        else

            r=mid2;

    }while(fabs(t1-t2)>0.00001);

    return t2;

}

int main()

{

   // freopen("r.txt","r",stdin);

    int N;

    point a,b,c,d,r,l,mid1,mid2;

    double t1,t2;

    cin>>N;

    while(N--)

    {

        cin>>a.x>>a.y>>b.x>>b.y;

        cin>>c.x>>c.y>>d.x>>d.y;

        cin>>p>>q>>R;

        l=a;r=b;

        do

        {

            mid1=(r/l);

            mid2=(r/mid1);

            t1=length(a,mid1)/p+find(c,d,mid1);

            t2=length(a,mid2)/p+find(c,d,mid2);

            if(t1>t2)

                l=mid1;

            else

                r=mid2;

        }while(fabs(t2-t1)>0.00001);

        printf("%.2f\n",t2);

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: