POJ 3286- How many 0's?(组合数学_区间计数)
来源:互联网 发布:万网域名证书生成器 编辑:程序博客网 时间:2024/06/10 03:26
How many 0's?
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uAppoint description:
Description
A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and n, m ≤ n. How many 0's will he write down?
Input
Input consists of a sequence of lines. Each line contains two unsigned 32-bit integers m and n, m ≤ n. The last line of input has the value of m negative and this line should not be processed.
Output
For each line of input print one line of output with one integer number giving the number of 0's written down by the monk.
Sample Input
10 11100 2000 5001234567890 23456789010 4294967295-1 -1
Sample Output
122929876543043825876150
题意:求区间内出现多少个零。和POJ 2282差不多。
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1LL b[12]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000};LL get_res(LL n){ int i; LL left,m; LL cnt=0; for(i=1;i<12;i++){ left=n/b[i]-1; cnt+=left*b[i-1]; m=(n%b[i]-n%b[i-1])/b[i-1]; if(m>0) cnt+=b[i-1]; else if(m==0) cnt+=n%b[i-1]+1; if(n<b[i]) break; } return cnt;}int main(){ LL n,m; while(~scanf("%lld %lld",&n,&m)){ if(n==-1&&m==-1) break; if(n>m) swap(n,m); printf("%lld\n",get_res(m)-get_res(n-1)); } return 0;}
0 0
- POJ 3286- How many 0's?(组合数学_区间计数)
- POJ 2282-The Counting Problem(组合数学_区间计数)
- UVa 11038 How Many 0's?(数学计数)
- UVA11038- How Many O's?(组合数学)
- Poj 3286 How many 0's? + Bzoj 1833 count 数字计数(数位统计)
- poj 3286 How many 0's?
- POJ 3286How many 0's?
- poj 3286 How many 0's?
- poj 3286 How many 0's?
- poj-3286-How many 0's?
- POJ 3286 How many 0's?
- POJ 3286 How many 0's?
- poj-3286 How many 0's?
- poj 3286 How Many 0's?
- POJ 3286 How many 0’s?
- uva 11038 How Many O's? 组合计数
- poj 3286 How many 0's? (数位DP+ 统计)
- poj 3286 How many 0's? --- 数位dp
- java文档注释
- OpenERP的价格表(Pricelist)机制
- android监听来电去电广播 .
- linux获取系统启动时间
- 【c语言】判断回文数组
- POJ 3286- How many 0's?(组合数学_区间计数)
- iOS-使用VPImageCropper时Analyze 出现Potential leak of an object stored into 'subImageRef'
- 深度学习大牛间的关系
- 查询多个ID的数据
- 编写随tomcat启动的自执行类
- 常用的ORCL函数
- export导出遇到ORA-19206 EXP-56 While Taking Export
- android 检测右滑的WebView
- Unity开发项目应该一开始规划好哪些内容?如何避免后期巨坑?