Bzoj 1857 [Scoi2010] conveyor belt three-point set

Source: Internet
Author: User

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", &AMP;A.X,&AMP;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)); }

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.