HDU 3400 Line belt (three-way)

Source: Internet
Author: User
Line belt

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1820 Accepted Submission (s): 683

Problem DescriptionIn a two-dimen=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?

 

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

 

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

 

Sample Input1 0 0 100 100 0 100 100 2 2 1

 

Sample Output136.60

 

Authorlxhgww & momodi

 

SourceHDOJ Monthly Contest-2010.05.01

 

Recommendlcy magic three-way method. Is the use of convex.
#include<stdio.h>#include<iostream>#include<math.h>#include<iostream>#include<algorithm>#include<string.h>using namespace std;const double eps=1e-5;struct point{    double x,y;};double dis(point a,point b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double p,q,r;double find2(point a,point c,point d){    point left,right;    point mid,midmid;    double t1,t2;    left=c;right=d;    do    {        mid.x=(left.x+right.x)/2;        mid.y=(left.y+right.y)/2;        midmid.x=(mid.x+right.x)/2;        midmid.y=(mid.y+right.y)/2;        t1=dis(a,mid)/r+dis(mid,d)/q;        t2=dis(a,midmid)/r+dis(midmid,d)/q;        if(t1>t2)left=mid;        else right=midmid;    }    while(dis(left,right)>=eps);    return t1;}double find(point a,point b,point c,point d){    point left,right;    point mid,midmid;    double t1,t2;    left=a;    right=b;    do    {        mid.x=(left.x+right.x)/2;        mid.y=(left.y+right.y)/2;        midmid.x=(mid.x+right.x)/2;        midmid.y=(mid.y+right.y)/2;        t1=dis(a,mid)/p+find2(mid,c,d);        t2=dis(a,midmid)/p+find2(midmid,c,d);        if(t1>t2)left=mid;        else right=midmid;    }while(dis(right,left)>=eps);    return t1;}int main(){    int T;    point a,b,c,d;    scanf("%d",&T);    while(T--)    {        scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);        scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);        scanf("%lf%lf%lf",&p,&q,&r);        printf("%.2lf\n",find(a,b,c,d));    }    return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.