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,&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); 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)