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;
}

 

转载于:https://www.cnblogs.com/MalcolmMeng/p/10029026.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值