其他分享
首页 > 其他分享> > NC20276 [SCOI2010]传送带

NC20276 [SCOI2010]传送带

作者:互联网

题目

1.题目大意

2.题目分析

3.题目代码

#include<bits/stdc++.h>

using namespace std;

const double eps=1e-4;//锁精度

double ax,ay,bx,by,cx,cy,dx,dy;
double P,Q,R;
double a1,a2,b1,b2;

inline void swap(double &x,double &y){
    double c;
    c=x,x=y,y=c;
}
inline double f(double x,double a,double b){//已知x以及两系数,求y 
    return a*x+b;
}
inline double far(double x,double y,double m,double n){//求两点之间的距离
    return sqrt((x-m)*(x-m)+(y-n)*(y-n));
}
inline double fi(double x,double y,double a,double b){
    double tim = far(x,y,a,b)/R;
    tim += far(x,y,dx,dy)/Q;
    return tim;
}
inline double suan(double x,double y){
    double tim = far(x,y,ax,ay)/P;//A到(x,y)的时间
    double l,r,ans,L,R;
    if(cx==dx){
        l = cy,r = dy;
        if(l>r){
            swap(l,r);
        }
        while(r-l>=eps){
            double lx=l+(r-l)/3,rx=r-(r-l)/3;
            L = fi(cx,lx,x,y), R = fi(cx,rx,x,y);
            if(L<=R){
                ans = L;
                r = rx;
                continue;
            } else {
                ans = R;
                l = lx;
            }
        }
    } else {
        l = cx,r = dx;
        if(l>r){
            swap(l,r);
        }
        while(r-l>=eps){//三分由(x,y)到CD上的某点 
            double lx = l + (r-l)/3,rx = r - (r-l)/3;
            L = fi(lx,f(lx,a2,b2),x,y), R = fi(rx,f(rx,a2,b2),x,y);
            if(L<=R){
                ans = L;
                r = rx;
                continue;
            } else {
                ans = R;
                l = lx;
            }
        }
    }
    return tim + ans;
}
int main(){
    cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;
    cin >> P >> Q >> R;
    if(ax!=bx){
        a1 = (ay-by) / (ax-bx);
        b1 = (ay-a1*ax);
    }
    if(cx!=dx){
        a2 = (cy-dy) / (cx-dx);
        b2 = (cy-a2*cx);
    }
    double l,r,ans,L,R;
    if(ax==bx){
        l = ay,r = by;
        if(l>r){
            swap(l,r);
        } 
        while(l<=r){
            double lx = l+(r-l)/3,rx = r-(r-l)/3;
            L = suan(ax,lx),R = suan(ax,rx);
            if(L<=R){
                ans = L;
                r = rx - eps;
                continue;
            } else {
                ans = R;
                l = lx + eps;
            }
        }
    } else {
        l = ax,r = bx;
        if(l>r){
            swap(l,r);
        }
        while(r-l>=eps){//三分由A到AB中的一点(不走AB即为从A到A) 
            double lx=l+(r-l)/3,rx=r-(r-l)/3;
            L=suan(lx,f(lx,a1,b1)),R=suan(rx,f(rx,a1,b1));
            if(L<=R){
                r = rx;
                ans = L;
                continue;
            } else {
                l = lx;
                ans = R;
            } 
        }
    } 
    printf("%.2lf",ans);
    return 0;
}

标签:传送带,double,rx,cx,ay,ax,NC20276,lx,SCOI2010
来源: https://www.cnblogs.com/zhangyi101/p/16612444.html