• BZOJ1857: [Scoi2010]传送带


    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1857

    三分套三分。

    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<cmath>
    #include<queue>
    #define rep(i,l,r) for (int i=l;i<=r;i++)
    #define down(i,l,r) for (int i=l;i>=r;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define maxn 100500
    #define eps 1e-3
    #define ll long long
    using namespace std;
    double ax,ay,bx,by,cx,cy,dx,dy,p,q,r;
    int read(){
        int x=0,f=1; char ch=getchar();
        while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
        while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    double sqr(double x){
        return x*x;
    }
    double dis(double x,double y,double xx,double yy){
        return sqrt(sqr(x-xx)+sqr(y-yy));
    }
    double cal(double x,double y){
        double lx=cx,ly=cy,rx=dx,ry=dy;
        while (fabs(lx-rx)>=eps||fabs(ly-ry)>=eps){
            double mx=(rx-lx)/3,my=(ry-ly)/3;
            double t1=dis(ax,ay,x,y)/p+dis(x,y,lx+mx,ly+my)/r+dis(lx+mx,ly+my,dx,dy)/q;
            double t2=dis(ax,ay,x,y)/p+dis(x,y,lx+mx*2,ly+my*2)/r+dis(lx+mx*2,ly+my*2,dx,dy)/q;
            if (t1<t2) {rx=lx+mx*2,ry=ly+my*2;}
            else {lx=lx+mx; ly=ly+my;}
        }
        return dis(ax,ay,x,y)/p+dis(x,y,lx,ly)/r+dis(lx,ly,dx,dy)/q;
    }
    int main(){
        scanf("%lf%lf%lf%lf",&ax,&ay,&bx,&by);
        scanf("%lf%lf%lf%lf",&cx,&cy,&dx,&dy);
        scanf("%lf%lf%lf",&p,&q,&r);
        double lx=ax,ly=ay,rx=bx,ry=by;
        while (fabs(lx-rx)>=eps||fabs(ly-ry)>=eps){
            double mx=(rx-lx)/3,my=(ry-ly)/3;
            double t1=cal(lx+mx,ly+my),t2=cal(lx+mx*2,ly+my*2);
            if (t1<t2) {rx=lx+mx*2,ry=ly+my*2;}
            else {lx=lx+mx; ly=ly+my;}
        }
        printf("%.2lf
    ",cal(lx,ly));
        return 0;
    }
  • 相关阅读:
    Xlua侧如何接受CSharp侧的可变参数
    C# 中如何精确地测量一段逻辑的执行时间
    C#中设计一个 ListPool 的方案
    unity中获取设备的信息
    Oracle-游标-取钱-存钱-转账
    Oracle 存储过程与java调用
    PL/SQL loop,while.for循环
    PL/SQL if case when
    PL/SQL %type %rowtype
    Oracle PLSQL入门
  • 原文地址:https://www.cnblogs.com/ctlchild/p/5034011.html
Copyright © 2020-2023  润新知