【二分】【codeforces817C】Really Big Numbers
来源:互联网 发布:淘宝素材主图图片大全 编辑:程序博客网 时间:2024/05/21 11:35
诶嘿嘿,题目传送门
题目描述
给定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 longusing 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;}
是不是很简单呢??
阅读全文
3 0
- 【二分】【codeforces817C】Really Big Numbers
- codeforces817c Really Big Numbers
- codeforces 817C Really Big Numbers 二分
- 【Codeforces 817C. Really Big Numbers】+ 二分
- codeforces 817C Really Big Numbers 二分
- Codeforces 817 C. Really Big Numbers 二分
- CodeFroces 817C Really Big Numbers(二分)
- C. Really Big Numbers
- C. Really Big Numbers
- 补题补题补题~~~~really big numbers
- Codeforces 817C Really Big Numbers【思维+二分】
- Educational Codeforces Round 23 C. Really Big Numbers(二分 数学)
- 【Codeforces 817 C. Really Big Numbers】+ 构造
- codeforces 817C Really Big Numbers
- Educational Codeforces Round 23 C. Really Big Numbers
- Educational Codeforces Round 23#C. Really Big Numbers
- Li Na really made a big upset,
- UVa10464 - Big Big Real Numbers
- letter-combinations-of-a-phone-number
- 神奇数字的数量 DFS深度优先搜索
- C语言中的Operator
- ZigBee设备渗透工具:Attify Z
- HTTP文件断点续传原理解析(源码)
- 【二分】【codeforces817C】Really Big Numbers
- 【知了堂学习笔记】分页查询—第二章
- 笨方法学python 15
- Informatica中lookup组件学习
- C语言根据国家英文首字母进行排序
- 【2017广西邀请赛】hdu 6184 Counting Stars 三元环+set
- docker常用命令
- 网络编程常见面试题
- 三种快速排序以及快速排序的优化