Topic link
http://www.lydsy.com/JudgeOnline/problem.php?id=1857 Thinking
http://blog.csdn.net/qpswwww/article/details/44465015 Code
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <
algorithm> #include <cmath> #define EPS 1e-4 using namespace std;
Double P,q,r,ax,ay,bx,by,cx,cy,dx,dy;
Inline Double dist (double x1,double y1,double x2,double y2) {return sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));}
Inline Double calc (double sx,double sy)//Leave conveyor belt AB {double lowerboundx=cx,upperboundx=dx at (Sx,sy);
Double Lowerboundy=cy,upperboundy=dy; while (Fabs (upperboundx-lowerboundx) >eps| | Fabs (Upperboundy-lowerboundy) >eps) {double midx1=lowerboundx+ (upperboundx-lowerboundx)/3,midx2=upperBoundx
-(UPPERBOUNDX-LOWERBOUNDX)/3;
Double midy1=lowerboundy+ (Upperboundy-lowerboundy)/3,midy2=upperboundy-(Upperboundy-lowerboundy)/3;
Double F1=dist (Ax,ay,sx,sy)/p+dist (sx,sy,midx1,midy1)/r+dist (midx1,midy1,dx,dy)/q;
Double F2=dist (Ax,ay,sx,sy)/p+dist (sx,sy,midx2,midy2)/r+dist (midx2,midy2,dx,dy)/q; if (f1<F2) Upperboundx=midx2,upperboundy=midy2;
else lowerboundx=midx1,lowerboundy=midy1;
Return Dist (ax,ay,sx,sy)/p+dist (Sx,sy,lowerboundx,lowerboundy)/r+dist (lowerboundx,lowerboundy,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,&P,&Q,&R);
Double lowerboundx=ax,upperboundx=bx;
Double Lowerboundy=ay,upperboundy=by; while (Fabs (upperboundx-lowerboundx) >eps| | Fabs (Upperboundy-lowerboundy) >eps) {double midx1=lowerboundx+ (upperboundx-lowerboundx)/3,midx2=upperBoundx
-(UPPERBOUNDX-LOWERBOUNDX)/3;
Double midy1=lowerboundy+ (Upperboundy-lowerboundy)/3,midy2=upperboundy-(Upperboundy-lowerboundy)/3;
Double F1=calc (midx1,midy1), F2=calc (MIDX2,MIDY2);
if (F1<F2) upperboundx=midx2,upperboundy=midy2;
else lowerboundx=midx1,lowerboundy=midy1;
printf ("%.2lf", Calc (Lowerboundx,lowerboundy));
return 0;
}