ask:
The speed of walking on AB is P, the speed on the CD is Q, the speed at the plane is R, now it's a minimum of how long it takes to go from a to D.
parsing: The
model is pretty good.
Find out where to go on AB is better, looking for this at the same time need to set up a search to find out where to go on the CD good.
But why not two points.
Because if we were two points, we find a point, there is no basis so that we can point to the left or to the right points, but for this question, suppose to find two points a,b if go A is better than go B, then the answer must be between AB, (it is said to be a physical problem do not ask me)
So we can three points out of the two, and then compare and then decide which side to divide.
Code:
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> #define EPS 1e-8 using namespace std;
Double p,q,r;
struct point {double x,y; Point () {} point (double _x,double _y): X (_x), Y (_y) {} friend istream& operator >> (IStream &_,point &am
P;a) {scanf ("%lf%lf", &A.X,&A.Y); return _;}
Point operator + (const point &a) {return point (X+A.X,Y+A.Y);}
Point operator-(const point &a) {return point (X-A.X,Y-A.Y);}
Point operator * (double rate) {return point (x*rate,y*rate);}
Double operator * (const point &a) {return x*a.x+y*a.y;}
Double operator ^ (const point &a) {return x*a.y-y*a.x;}
Friend Double Get_dis (point A,point b) {return sqrt (a-b) * (A-b));
}}a,b,c,d;
Double Calc (Point a) {point L (c.x,c.y), R (D.X,D.Y); while (Fabs (r.x-l.x) >eps| |
Fabs (R.Y-L.Y) >eps) {point tri1=l+ (r-l) * (1.0/3); Point tri2=l+ (r-l) * (2.0/3);
Double Cost1=get_dis (a,a)/p+get_dis (A,TRI1)/r+get_dis (tri1,d)/q;
Double Cost2=get_dis (a,a)/p+get_dis (a,tri2)/r+get_dis (tri2,d)/q;
if (cost1>cost2) L=tri1;
else R=tri2;
Return Get_dis (a,a)/p+get_dis (a,l)/r+get_dis (l,d)/q;
int main () {cin>>a>>b>>c>>d;
scanf ("%lf%lf%lf", &p,&q,&r);
Point L (A.X,A.Y);
Point R (B.X,B.Y); while (Fabs (r.x-l.x) >eps| |
Fabs (R.Y-L.Y) >eps) {point tri1=l+ (r-l) * (1.0/3);
Point tri2=l+ (r-l) * (2.0/3);
Double Cost1=calc (TRI1);
Double Cost2=calc (TRI2);
if (cost1>cost2) L=tri1;
else R=tri2;
printf ("%.2lf\n", Calc (l)); }