3286 How many 0's? 计算(n,m)中有多少个0
2010-10-04 10:30
176 查看
How many 0's?
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
Sample Output
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 1744 | Accepted: 816 |
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 11 100 200 0 500 1234567890 2345678901 0 4294967295 -1 -1
Sample Output
1 22 92 987654304 3825876150
#include "iostream" #include "cstring" #include "cstdio" #include "cmath" using namespace std; __int64 n,m; struct node { __int64 num[12]; }cnt,res; void prntf(node nn) { printf("%I64d/n",nn.num[0]); } node countnum(__int64 t)//过程(1-t) 中(0-9)的总个数 { if(t==-1) {node tt;memset(tt.num,0,sizeof(tt.num));tt.num[0]=-1;return tt;} __int64 times=1,temp,td; __int64 i,j,start; node tmp; memset(tmp.num,0,sizeof(tmp.num)); while (t>=times) { td=t/(times*10); for (i=0;i<=9;i++) tmp.num[i]+=td*times; if (td) tmp.num[0]-=times; temp=(t/times)%10;//当前尾数 if (t>=times*10)//若只剩一位数的时候0是不要算的 因为我们是从1开始的 j=0; else j=1; for (i=j;i<temp;i++) tmp.num[i]+=times; tmp.num[temp]+=t%times+1; times*=10; } return tmp; } void solve() { __int64 i,j; node a,b; a=countnum(n-1);a.num[0]++; b=countnum(m);b.num[0]++; node c; for (i=0;i<10;i++) c.num[i]=b.num[i]-a.num[i]; prntf(c);
} int main() { //freopen("R:/in.txt","r",stdin); while (scanf("%I64d%I64d",&n,&m)!=EOF) { if (n==-1&&m==-1) break; solve(); }
}
相关文章推荐
- poj 3286 How many 0's? --- 数位dp
- How many 0's? - POJ 3286 数位dp
- POJ 3286 How many 0's?(数位dp)
- Poj 3286 How many 0's? + Bzoj 1833 count 数字计数(数位统计)
- 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? (数位dp)
- POJ 3286 How many 0's?(数位DP)
- poj 3286 How many 0's?
- POJ 3286 How many 0's?
- POJ 2282 The Counting Problem & POJ 3286 How many 0's?(按位计算贡献)
- POJ 3286 How many 0's?
- poj 3286 How many 0's? 按位统计
- POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
- Lua-计算表中有多少个元素-#table的用法
- [HDU] 1903 Exchange Rates 计算炒外汇最佳投机能赚多少钱的
- Java 计算两个日期直接相差多少天
- 计算节占用多少页