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
three-point-AB, CD-Walk path length
The result is the card precision ... gg
think you can't waste too much time (local test 6000+ group data are all right ...)
To be decadent ...
#include <cmath>#include<cstdio>#include<algorithm>using namespacestd;intRead_p,read_ca,read_f;inlineintRead () {read_p=0; Read_ca=getchar (); read_f=1; while(read_ca<'0'|| Read_ca>'9') {if(read_ca=='-') read_f=-1; read_ca=GetChar ();} while(read_ca>='0'&&read_ca<='9') read_p=read_p*Ten+read_ca- -, read_ca=GetChar (); returnread_p*Read_f;}intXa,ya,xb,yb,xc,yc,xd,yd,p,q,r;Long DoubleZ1,z2;inlineDoubleGDoubleADoubleb) { Doublexx1,yy1,xx2,yy2,zz1,zz2; ZZ1=a/z1;zz2=b/Z2; Xx1=xa+ (XB-XA) *zz1; Yy1=ya+ (Yb-ya) *zz1; XX2=xd+ (XC-XD) *zz2; Yy2=yd+ (yc-yd) *zz2; returnA/p+b/q+sqrt ((xx2-xx1) * (xx2-xx1) + (yy2-yy1) * (yy2-yy1))/R;} InlineDoubleFDoublex) { DoubleL=0, r=z2,mid1,mid2,w; while(r-l>=1e-Ten) {W= (r-l)/3.0; mid1=l+w;mid2=mid1+W; if(g (X,MID1) >g (X,MID2)) L=mid1;ElseR=Mid2; } returng (x,l);}intMain () {/*freopen ("a.in", "R", stdin); Freopen ("A.out", "w", stdout);*/xa=read (); Ya=read (); Xb=read (); Yb=read (); Xc=read (); Yc=read (); Xd=read (); yd=read (); Z1=sqrt ((XB-XA) * (XB-XA) + (Yb-ya) * (Yb-ya)), Z2=sqrt ((XD-XC) * (XD-XC) + (YD-YC) * (yd-YC)); P=read (); Q=read (); r=read (); DoubleL=0, r=z1,mid1,mid2,w; while(r-l>1e-Ten) {W= (r-l)/3.0; mid1=l+w;mid2=mid1+W; if(f (MID1) >f (MID2)) L=mid1;ElseR=Mid2; } printf ("%.2lf\n", F (L));}
View Code
bzoj1857: [Scoi2010] Conveyor belt