zoukankan      html  css  js  c++  java
  • codeforces 817C Really Big Numbers

    注意到一点,如果x是Really Big Number,那么x+1一定是Really Big Number

    原因是sumd(x+1)一定不超过sumd(x)+1 sumd表示各个数位的数字之和

    所以在序列中存在一个数字,这个数字之前全不是Really Big Number,它和他之后的

    全是Really Big Number,通过二分就可以找到这个数字

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<queue>
    #include<map>
    #include<unordered_map>
    #define DEBUG(x) cout<<#x<<" = "<<x<<endl
    using namespace std;
    typedef long long ll;
    ///二分可以用在单调序列上,也可以用在性质发生变化的序列上
    ll n,s;
    bool judge(ll m)
    {
        ll t=m;
        ll dsum=0;
        while(t){
            dsum+=t%10;
            t/=10;
        }
        return m-dsum>=s;
    }
    int main()
    {
    //    freopen("in.txt","r",stdin);
        cin>>n>>s;
        ll l=1,r=n;
        ll lp=-1;
        while(l<=r){
            ll mid=(l+r)>>1;
            if(judge(mid)){
                lp=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        ll ans=lp==-1?0:n-lp+1;
        cout<<ans<<endl;
    }
  • 相关阅读:
    nodeJs-querystring 模块
    nodeJs-process对象
    nodejs-Path模块
    nodejs-os模块
    nodejs-CommonJS规范
    nodejs-Events模块
    nodejs-Http模块
    nodejs-Cluster模块
    转:AOP与JAVA动态代理
    转:jdk动态代理实现
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/10029026.html
Copyright © 2011-2022 走看看