【二分】【codeforces817C】Really Big Numbers
2017-09-08 20:20
337 查看
诶嘿嘿,题目传送门
输出满足数的个数 (1 ≤ n, s ≤ 10^18).
题目描述
给定n和s,求出1——n中有多少数满足该数减去其所有数位数字之和大于或等于s的性质输出满足数的个数 (1 ≤ n, s ≤ 10^18).
思路
首先我们观察一下这题其实和个位没有什么关系,因为个位已经减去,所以每十个数得到的结果是一样的,我们通过规律可知,该数减去其所有数位数字之和是一个单调递增的函数,所以我们二分答案即可代码
#include <cstdio> #include <cstdlib> #include <ctime> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #define ll long long using namespace std; ll n,S,an; int a[10001]; inline void fj(ll x){ an=0; while(x>0)a[++an]=x%10,x/=10; } inline ll check(ll w){ if(w==0) return 0; fj(w); for(int i=1;i<=an;++i)w-=a[i]; return w; } int main(){ scanf("%lld%lld",&n,&S); ll l=0,r=n; while(l<r){ ll mid=(l+r)>>1; if(check(mid)<S)l=mid+1; else r=mid; } r=r-r%10; if(check(r)>=S)cout<<n-r+1; else cout<<0; return 0; }
是不是很简单呢??
相关文章推荐
- CF - 817C. Really Big Numbers - 二分+数学
- 【Codeforces 817C. Really Big Numbers】+ 二分
- codeforces817c Really Big Numbers
- Educational Codeforces Round 23 C. Really Big Numbers(二分 数学)
- B - Really Big Numbers
- Educational Codeforces Round 23 C. Really Big Numbers
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
- C. Really Big Numbers
- C. Really Big Numbers
- C. Really Big Numbers
- 【Codeforces 817 C. Really Big Numbers】+ 构造
- 【 【henuacm2016级暑期训练】动态规划专题 K】 Really Big Numbers
- CF817C Really Big Numbers
- 补题补题补题~~~~really big numbers
- 315.leetcode Count of Smaller Numbers After Self(hard)[利用二分查找 空间换取时间的思想]
- CSUOJ nineteen thirteen One big silly dragon gives gifts out 线段树 二分 转化
- UVa 10220 - I Love Big Numbers !
- CodeForces 359 D.Pair of Numbers (二分+ST)
- [BZOJ2986]Non-Squarefree Numbers(二分+容斥原理)
- BZOJ 2986: Non-Squarefree Numbers [容斥原理 二分]