zoukankan      html  css  js  c++  java
  • CodeForces 670D Magic Powder

    二分。

    二分一下答案,然后验证一下。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c=getchar(); x=0;
        while(!isdigit(c)) c=getchar();
        while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
    }
    
    const int maxn=100010;
    LL k,a[maxn],b[maxn];
    int n;
    
    bool check(LL x)
    {
        LL sum=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]*x<=b[i]) continue;
            sum=sum+a[i]*x-b[i];
            if(sum>k) return 0;
        }
        if(sum<=k) return 1;
        return 0;
    }
    
    int main()
    {
        scanf("%d%lld",&n,&k);
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
    
        LL L=0,R=3e9,ans;
        while(L<=R)
        {
            LL mid=(L+R)/2;
            if(check(mid)) L=mid+1,ans=mid;
            else R=mid-1;
        }
        printf("%lld
    ",ans);
    
        return 0;
    }
  • 相关阅读:
    第四章:活动图
    makefile
    C语言中,头文件和源文件的关系(转)
    第三章:用例图
    第二章:建模基础
    shell编程:if语句
    shell编程:for循环
    shell基础:数值运算与运算符
    shell基础:预定义变量
    图片异步加载的几种实现方案
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5899578.html
Copyright © 2011-2022 走看看