"BZOJ-1857" Conveyor three-part set three points

Source: Internet
Author: User

1857: [Scoi2010] Belt time limit:1 Sec Memory limit:64 MB
submit:1077 solved:575
[Submit] [Status] [Discuss] The description has two conveyors on a 2-dimensional plane, each of which can be seen as a line segment. Two conveyor belts are segment AB and segment CD respectively. The movement speed of the LXHGWW on AB is P, the speed of movement on the CD is Q, and the moving speed on the plane is R. Now LXHGWW wants to go from point A to point D, he wants to know at least how long it takes. Input data the first line is 4 integers, representing the coordinates of a and B, respectively, ax,ay,bx,by the second row is 4 integers, representing the coordinates of C and D, respectively, Cx,cy,dx,dy The third line is 3 integers, p,q,routput output data is a row, indicating lxhgww from point A to D point of the shortest time, reserved to 2 digits after the decimal point sample Input0 0 0 100
100 0 100 100
2 2 1
Sample Output136.60
HINT

For 100% of data, 1<= ax,ay,bx,by,cx,cy,dx,dy<=1000
1<=p,q,r<=10

Source

Day2

Solution

Three-part method, which is used to find the extremum problem of single-peak function, is very good thinking

Given the left and right endpoint l,r; Find two thirds points m1,m2 (l<=m1<=m2<=r), M2 if M1 is better than l=m1, otherwise r=m2

This problem, first, the relationship is very easy to find, found to be a single-peak function, then three points to find the most value can

But here's the three-point set of three points, also very good understanding

For the outer three m1,m2, if the size of the comparison, it is necessary to make three points inside to determine, this is three points set three points

Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}#defineEPS 1e-3intAx,ay,bx,by,cx,cy,dx,dy,p,q,r;DoubleDistDoubleX1,DoubleY1,DoubleX2,Doubley2) {    returnsqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));}DoubleCalc (DoubleXDoubleY) {    Doublelx=cx,ly=cy,rx=dx,ry=Dy;  while(Fabs (RX-LX) >eps | | fabs (ry-ly) >EPS) {            Doublemx1=lx+ (RX-LX)/3, my1=ly+ (ry-ly)/3, mx2=lx+ (RX-LX)/3*2, my2=ly+ (ry-ly)/3*2; DoubleLl=dist (ax,ay,x,y)/p+dist (x,y,mx1,my1)/r+dist (mx1,my1,dx,dy)/p; DoubleRr=dist (ax,ay,x,y)/p+dist (x,y,mx2,my2)/r+dist (mx2,my2,dx,dy)/p; if(LL&GT;RR) lx=mx1,ly=My1; Elserx=mx2,ry=My2; }    returnDist (ax,ay,x,y)/p+dist (x,y,lx,ly)/r+dist (lx,ly,dx,dy)/Q;}intMain () {Ax=read (); Ay=read (); Bx=read (); by=read (); Cx=read (); Cy=read (); Dx=read (); dy=read (); P=read (); Q=read (); R=read (); Doublelx=ax,ly=ay,rx=bx,ry=by ;  while(Fabs (RX-LX) >eps | | fabs (ry-ly) >EPS) {            Doublemx1=lx+ (RX-LX)/3, mx2=lx+ (RX-LX)/3*2, my1=ly+ (ry-ly)/3, my2=ly+ (ry-ly)/3*2; DoubleLl=calc (mx1,my1), rr=Calc (MX2,MY2); if(LL&GT;RR) lx=mx1,ly=My1; Elserx=mx2,ry=My2; } printf ("%.2lf\n", Calc (lx,ly)); return 0;}

I would say because the variable name WA 3 rounds .... A Sad Story ...

"BZOJ-1857" Conveyor three-part set 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.