码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 23C

时间:2017-06-21 23:06:29      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:string   注意   using   b16   for   ret   超级   linker   vector   

超级坑的水题!!!想了两天没一点思路,看了题解第一段话就做出来了

刚开始一直在想找到通项就是例如an*10^n+...+a0*10^0-an-...-a0>=s,然后从这个里面找到规律,结果走进死胡同了

Let‘s prove that if x is really big, then x?+?1 is really big too.

证明很容易,我就不证了,直接上代码,二分答案就行了

还有一点要注意,因为是10E18范围,所以平时循环50次是不够用的,加到了70次就ac了,也可以用l<r-1这个来判断

技术分享
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-9;
const int N=100000+10,maxn=111117,inf=11111;

ll n,s;
bool ok(ll x)
{
    ll t=x,p=x;
    while(p){
        t-=(p%10);
        p/=10;
    }
    return t>=s;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>s;
    ll l=1,r=n+1;
    for(int i=0;i<70;i++)
    {
        ll m=(l+r)/2;
        if(ok(m))r=m;
        else l=m;
    }
    cout<<n-l<<endl;
    return 0;
}
View Code

 

Educational Codeforces Round 23C

标签:string   注意   using   b16   for   ret   超级   linker   vector   

原文地址:http://www.cnblogs.com/acjiumeng/p/7061879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!