Hdu 3400 (three points)

Source: Internet
Author: User

Topic Link: Click to open the link;
Test instructions: Given two line segments, one segment endpoint is a, B, and the other segment endpoint is c,d, at different speeds on two segments and not on the segment, to find the shortest time.

Analysis: The subject a total of three time, on a-B, on the c-d, in the blank place. The three time period is x, Y, Z. Then once the X and Y are determined, Z can be determined, because the points on the two segments are determined, Z is also found, if x determines when Y is not sure, Z and y have a relationship, so time is an extremum, think of the extremum, it should be three points to find the most suitable y. For X, the three-point solution to X can get the extremum of y of the corresponding points, and we can find the extremum of y of the team. That's the solution.

The code is as follows:

#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < Iostream> #include <algorithm>using namespace Std;const double Eps=1e-7;const double ee=1e-9;struct point{Doub Le x, y;}; Double Dis (point A,point b) {return sqrt (ee+ (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Double q,p,r;    Point a,b,c,d,tmpx,tmpy;double call (Double t) {tmpy.x=d.x+ (c.x-d.x)/dis (c,d) *t*q;    tmpy.y=d.y+ (C.Y-D.Y)/dis (c,d) *t*q; Return T+dis (tmpx,tmpy)/R;}    Double Sanfen (Double t) {tmpx.x=a.x+ (b.x-a.x)/dis (A, b) *t*p;    tmpx.y=a.y+ (B.Y-A.Y)/dis (A, b) *t*p;    Double Low,high,mid,midd;    low=0;    High=dis (c,d)/q;        while (high-low>eps) {mid= (Low+high)/2;        Midd= (Mid+high)/2;        if (Call (mid) <call (Midd)) High=midd;    else Low=mid;                                    } return T+call (mid);    }//Three points for Y value int main () {int t;    scanf ("%d", &t); while (t--) {scanf ("%lf%lf%lf%lf", &amP;A.X,&AMP;A.Y,&AMP;B.X,&AMP;B.Y);        scanf ("%lf%lf%lf%lf", &AMP;C.X,&AMP;C.Y,&AMP;D.X,&AMP;D.Y);        scanf ("%lf%lf%lf", &p,&q,&r);        Double Low,high,mid,midd;        low=0;        High=dis (A, B)/p;            while (high-low>eps) {mid= (Low+high)/2;            Midd= (Mid+high)/2;            if (Sanfen (mid) <sanfen (Midd)) High=midd;        else Low=mid;    }//Three to find the value of x printf ("%.2f\n", Sanfen (mid)); } return 0;}


Hdu 3400 (three points)

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.