zoukankan      html  css  js  c++  java
  • 二分

    1 codeforces 371

    汉堡的组成

    已经有的数目

    小店里买的价格

    自己有的钱

    二分汉堡的个数

    #include <iostream>
    #include<string.h>
    #include<stdio.h>
    #include<algorithm>
    #include<string>
    using namespace std ;
    
    #define LL __int64
    #define MAXN 200010
    #define inf  1000000000000000
    
    int main()
    {
        LL b,s,c;
        b=s=c=0;
        string s1;
        cin>>s1;
        LL b1,s11,c1,pb,ps,pc,pri;
        cin>>b1>>s11>>c1>>pb>>ps>>pc>>pri;
        LL l=0,r=inf;
        int len=s1.size();
        for(int i=0;i<len;i++)
        {
            if(s1[i]=='B')
                b++;
            else if(s1[i]=='S')
                s++;
            else
                c++;
        }
        LL num=0;
    
        while(l<=r)
        {
            LL mid=(l+r)>>1;
            LL b2=mid*b;
            LL s2=mid*s;
            LL c2=mid*c;
            LL ans=0;
            b2=max(b2-b1,(LL)0);
            c2=max(c2-c1,(LL)0);
            s2=max(s2-s11,(LL)0);
            ans = b2*pb + s2*ps + c2*pc;
            //printf("%")
            if(ans>pri)
                r=mid-1;
            else
            {
                l=mid+1;
                num=max(num,mid);
            }
        }
        printf("%I64d
    ",num);
        return 0;
    }
    View Code

    POJ 3273

    n 天 要分成恰好 连续m个月

    然后是n个数字

    要 n个月的最大值最小

    二分 这个值 范围是 max   sum

    #include <iostream>
    #include<string.h>
    #include<stdio.h>
    #include<algorithm>
    #include<string>
    using namespace std ;
    
    #define LL __int64
    #define MAXN 200010
    #define inf  100000000000
    
    LL mo[MAXN];
    
    int main()
    {
        int n,day;
        scanf("%d%d",&n,&day);
        LL l=0,r,mid,sum1=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&mo[i]);
            l=max(l,mo[i]);
            sum1+=mo[i];
        }
        r=sum1;
        while(l<=r)
        {
            mid=(l+r)>>1;
            LL cnt=1,sum=0;
    
            for(int i=1;i<=n;i++)
            {
                sum+=mo[i];
                if(sum>mid)
                {
                    sum=mo[i];
                    cnt++;
                }
            }
            if(cnt<=day)
                r=mid-1;
            else
                l=mid+1;
         //   printf("%d %d %d
    ",l,r,mid);
        }
        printf("%I64d
    ",mid);
        return 0;
    }
    View Code

    HDU  2675

    使得上面那个式子成立的 x的解

    显然  至少有1 个解 x =e*y

    然后要取一下 对数  e*y ln x =  x * ln (e y)

     ln x / x = ln(e y) / (e y)

    然后左边那个函数差不多可以看出来趋势  求一下导数

    一般有2 解  e的时候有1 解

    1 - e  二分 x 的 值 很漂亮

    #include <iostream>
    #include<string.h>
    #include<stdio.h>
    #include<algorithm>
    #include<string>
    #include<math.h>
    
    using namespace std ;
    
    #define e 2.7182818284
    #define LL __int64
    #define MAXN 200010
    #define inf  1000000000
    
    int mo[MAXN];
    
    int main()
    {
        double y;
        while(scanf("%lf",&y)!=EOF)
        {
            if(y==1)
                printf("2.71828
    ");
            else
            {
                double ans;
                double l=1,r=e,en;
                en = (1 + log(y)/log(e))/(e*y);
                while(r-l>1e-8)
                {
                    double mid=(l+r)/2;
                   // printf("%lf %lf
    ",l,r);
                    if(log(mid)/log(e)/mid-en>1e-8)
                        r=mid;
                    else
                        l=mid;
    
                }
                printf("%.5lf ",l);
                printf("%.5lf
    ",y*e);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    ansible设置串行的方法
    给k8s集群中的node节点加标签
    Prometheus断电后启动异常 Error on ingesting samples
    配置 containerd 镜像仓库完全攻略
    这款网络排查工具,堪称神器!
    k8s备份工具之velero
    CentOS 7安装megacli
    Atitit .h5文件上传 v3
    php切片处理视频大文件思路
    php切片处理视频大文件功能
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6491882.html
Copyright © 2011-2022 走看看