• bzoj1857: [Scoi2010]传送带(三分套三分)


      经典题...

      不知道怎么证单峰函数

      三分第一个传送带的位置里套三分另一个传送带的位置,计算答案

    #include<bits/stdc++.h>
    #define ll long long 
    using namespace std;
    const int maxn=500010,inf=1e9;
    const double eps=1e-6;
    int ax,ay,bx,by,cx,cy,dx,dy,p,q,r;
    void read(int &k)
    {
        int f=1;k=0;char c=getchar();
        while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
        while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
        k*=f;
    }
    double dis(double x1,double y1,double x2,double y2)
    {return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
    double calc(double x,double y)
    {
        double lx=cx,ly=cy,rx=dx,ry=dy;
        while(fabs(rx-lx)>eps||fabs(ry-ly)>eps)
        {
            double midx1=lx+(rx-lx)/3,midy1=ly+(ry-ly)/3;
            double midx2=lx+((rx-lx)/3*2),midy2=ly+((ry-ly)/3*2);
            double dis1=dis(ax,ay,x,y)/p+dis(x,y,midx1,midy1)/r+dis(midx1,midy1,dx,dy)/q;
            double dis2=dis(ax,ay,x,y)/p+dis(x,y,midx2,midy2)/r+dis(midx2,midy2,dx,dy)/q;
            if(dis1-dis2>eps)lx=midx1,ly=midy1;
            else rx=midx2,ry=midy2;
        }
        return dis(ax,ay,x,y)/p+dis(x,y,lx,ly)/r+dis(lx,ly,dx,dy)/q;
    }
    int main()
    {
        read(ax);read(ay);read(bx);read(by);
        read(cx);read(cy);read(dx);read(dy);
        read(p);read(q);read(r);
        double lx=ax,ly=ay,rx=bx,ry=by;
        while(fabs(rx-lx)>eps||fabs(ry-ly)>eps)
        {
            double midx1=lx+(rx-lx)/3,midy1=ly+(ry-ly)/3;
            double midx2=lx+((rx-lx)/3*2),midy2=ly+((ry-ly)/3*2);
            if(calc(midx1,midy1)-calc(midx2,midy2)>eps)lx=midx1,ly=midy1;
            else rx=midx2,ry=midy2;
        }
        printf("%.2lf",calc(lx,ly));
        return 0;
    }
    View Code
  • 相关阅读:
    验证身份证
    base64.js
    mysql常用操作
    drop、truncate和delete的区别
    安装mysql
    一些常用计算
    nuxt+vant+rem项目构建
    vue2安装sass 预编译
    vant ui rem配置流程
    关于vue项目和内嵌iframe页面之间的通信问题
  • 原文地址:https://www.cnblogs.com/Sakits/p/7441763.html
Copyright © 2020-2023  润新知