SCOI2010 传送带

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define eps 1e-9
double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,P,Q,R;
inline double dis(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
inline double calc(double x,double y){
    double Ex=Ax+(Bx-Ax)*x,Ey=Ay+(By-Ay)*x,Fx=Cx+(Dx-Cx)*y,Fy=Cy+(Dy-Cy)*y;
    return dis(Ax,Ay,Ex,Ey)/P+dis(Ex,Ey,Fx,Fy)/R+dis(Fx,Fy,Dx,Dy)/Q;
}
inline double check(double x){
    double l=0,r=1,lm,rm;
    for(;r-l>eps;){
        lm=l+(r-l)/3;
        rm=r-(r-l)/3;
        if(calc(x,lm)>calc(x,rm))
            l=lm;
        else r=rm;
    }
    return calc(x,l);
}
int main(){
    scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&Ax,&Ay,&Bx,&By,&Cx,&Cy,&Dx,&Dy,&P,&Q,&R);
    double l=0,r=1,lm,rm;
    for(;r-l>eps;){
        lm=l+(r-l)/3;
        rm=r-(r-l)/3;
        if(check(lm)>check(rm))
            l=lm;
        else r=rm;
    }
    printf("%.2lf",check(l));
    return 0;
}
posted @ 2019-03-13 13:46 Pelom 阅读(...) 评论(...) 编辑 收藏