Bzoj 1857 [Scoi2010] conveyor belt __bzoj-1857

Source: Internet
Author: User
Tags abs

Three points.

Three points AB on the point, repeatedly points on the CD can be (visual but I too weak will not permit, later will prove the process of supplementary proof).

Note that line segments degenerate into dots, so it's best not to count the answers at three points (where the pit Qaq)

#include <cmath> #include <cstdio> #include <algorithm> using namespace std;
const double eps=1e-3;
Double ax,ay,bx,by,cx,cy,dx,dy,p,q,r; Double dis (double x1,double y1,double x2,double y2) {return sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));} Double tri (doubl
    e x, double y) {double lx=cx,ly=cy,rx=dx,ry=dy,mx1,my1,mx2,my2,r1,r2;
        while (ABS (LX-RX) >eps | | ABS (LY-RY) >eps) {mx1=lx+ (RX-LX)/3;mx2=lx+2* (RX-LX)/3;
        my1=ly+ (ry-ly)/3;my2=ly+2* (ry-ly)/3;
        R1=dis (x,y,mx1,my1)/r+dis (mx1,my1,dx,dy)/q;
        R2=dis (x,y,mx2,my2)/r+dis (mx2,my2,dx,dy)/q;
        if (R1&GT;R2) lx=mx1,ly=my1;
    else Rx=mx2,ry=my2;
return dis (x,y,lx,ly)/r+dis (lx,ly,dx,dy)/q; int main () {scanf ("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &ax,&ay,&bx,&by,&cx,&cy,&dx,&
    AMP;DY,&AMP;P,&AMP;Q,&AMP;R);
    Double lx=ax,ly=ay,rx=bx,ry=by,mx1,my1,mx2,my2,r1,r2; while (ABS (LX-RX) >eps | | ABS (LY-RY) >eps) {mx1=lx+ (RX-LX)/3;mx2=lx+2* (RX-LX)/3;
        my1=ly+ (ry-ly)/3;my2=ly+2* (ry-ly)/3;
        R1=tri (mx1,my1) +dis (ax,ay,mx1,my1)/p;
        R2=tri (mx2,my2) +dis (ax,ay,mx2,my2)/p;
        if (R1&GT;R2) lx=mx1,ly=my1;
    else Rx=mx2,ry=my2;
printf ("%.2lf\n", Tri (lx,ly) +dis (ax,ay,lx,ly)/p); }

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.