Description

Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be
1024 1025 1026 1027 1028 1029 1030 1031 1032

there are ten 0's in the list, ten 1's, seven 2's, three 3's, and etc.

Input

The input consists of up to 500 lines. Each line contains two numbers a and b where 0 < a, b < 100000000. The input is terminated by a line `0 0', which is not considered as part of the input.

Output

For each pair of input, output a line containing ten numbers separated by single spaces. The first number is the number of occurrences of the digit 0, the second is the number of occurrences of the digit 1, etc.

Sample Input

1 10
44 497
346 542
1199 1748
1496 1403
1004 503
1714 190
1317 854
1976 494
1001 1960
0 0

Sample Output

1 2 1 1 1 1 1 1 1 1
85 185 185 185 190 96 96 96 95 93
40 40 40 93 136 82 40 40 40 40
115 666 215 215 214 205 205 154 105 106
16 113 19 20 114 20 20 19 19 16
107 105 100 101 101 197 200 200 200 200
413 1133 503 503 503 502 502 417 402 412
196 512 186 104 87 93 97 97 142 196
398 1375 398 398 405 499 499 495 488 471
294 1256 296 296 296 296 287 286 286 247
 
题意:求出区间内0~9的个数
思路:dp[i][j],代表长度为i的数字里面共有几个j
 
 
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; __int64 dp[9] = {1,10,100,1000,10000,100000,1000000,10000000,100000000};
//只考虑以某个数开头,例如9XXX,不算XXX里的9,共头1000个9
__int64 solve(__int64 n,__int64 pos)
{
__int64 left,m,sum = 0;
__int64 i;
for(i = 1; i<9; i++)
{
left = n/dp[i];//以123为例,第一次循环求出得出12
if(!pos)
left--;
sum+=left*dp[i-1];//12后面的数,每种都只有1个
m = (n%dp[i]-n%dp[i-1])/dp[i-1];//求出12后面的数确切是什么
if(m>pos)
sum+=dp[i-1];//因为m>pos,所以pos的数目即为m后面所有这个数字的和,而m是第i位,所以总和加上dp[i-1]
else if(m==pos)
sum+=n%dp[i-1]+1;//求出m后的数字是几,总数还要加上m本身的个数
if(n<dp[i])//退出条件
break;
}
return sum;
} int main()
{
__int64 n,m;
__int64 i;
while(~scanf("%I64d%I64d",&n,&m),n+m)
{
if(n>m)
swap(n,m);
printf("%I64d",solve(m,0)-solve(n-1,0));
for(i = 1; i<=9; i++)
printf(" %I64d",solve(m,i)-solve(n-1,i));
printf("\n");
} return 0;
}

POJ2282:The Counting Problem(数位DP)的更多相关文章

  1. 『The Counting Problem 数位dp』

    The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结 ...

  2. UVA - 1640 The Counting Problem (数位dp)

    题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示 ...

  3. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  4. hiho1259 A Math Problem (数位dp)

    题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 ...

  5. 哈尔滨工程大学ACM预热赛 G题 A hard problem(数位dp)

    链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) {     if ( ...

  6. POJ2282 The Counting Problem

    题意 Language:DefaultEspañol The Counting Problem Time Limit: 3000MS Memory Limit: 65536K Total Submis ...

  7. POJ2282 The Counting Problem(数位DP)

    用dp[pos][val][cnt]表示状态,pos是数位,val是当前统计的数字,cnt是目前统计的目标数字的出现次数 注意状态的转移过程,统计数字0时前导0的影响. 1 #include<c ...

  8. nowcoder A hard problem /// 数位DP

    题目大意: 称一个数x的各个数位之和为f(x) 求区间L R之间 有多少个数x%f(x)==0 #include <bits/stdc++.h> using namespace std; ...

  9. Gym - 102040B Counting Inversion (数位dp)

    题意:求[a,b]区间内的数字中正序对的个数. 具体思路参考: https://blog.csdn.net/weixin_43135318/article/details/88061396 https ...

随机推荐

  1. RobotFramework-调用.py文件

    RobotFramework-调用.py文件,直接运行: 注意:文件路径的\全部换成好了/

  2. Invalid object name ‘sys.configurations’. (Microsoft SQL Server, Error: 208)

    http://blogs.msdn.com/b/ramaprasanna/archive/2009/09/16/invalid-object-name-sys-configurations-micro ...

  3. 1.C#基础篇-->封装、继承和多态

    面向对象三要素:封装.继承和多态.正确理解这三个要素,才能在编程中建立面向对象的思想. 1.封装使用篇 作用:好的封装增加代码的可读性,易于维护. 什么情况下使用封装,封装的原则是? 1>功能相 ...

  4. 编译器手工开栈(hdu可以其他可以尝试)

    做题的时候经常遇到深度递归的,当然也可以改成非递归形式.如果写成递归形式会爆栈,所以可以用手工扩展栈. C++ (一般用C++提交,所以就推荐这种了) #pragma comment(linker, ...

  5. JNA使用

    JNA与C对应的数据类型: 注意:        使用byte[]对应C++中的char* 可以返回函数执行的结果值 一.添加JNA需要的jar包      1.jna.jar      2.plat ...

  6. poj 1273 Drainage Ditches 最大流入门题

    题目链接:http://poj.org/problem?id=1273 Every time it rains on Farmer John's fields, a pond forms over B ...

  7. javascript版Ajax请求

    什么是Ajax请求,Ajax也就是“Asynchronous JavaScript and XML”(异步JavaScript和XML),无刷新数据读取.能减少流量的消耗,也提高了浏览的流畅性,给用户 ...

  8. 表单中<form>的enctype属性

    application/x-www-form-urlencoded.multipart/form-data.text/plain 上传文件的表单中<form>要加属性enctype=&qu ...

  9. Sqli-labs less 49

    Less-49 本关与47关基本类似,区别在于没有错误回显,所以我们可以通过延时注入和导入文件进行注入. 利用延时注入 http://127.0.0.1/sqli-labs/Less-49/?sort ...

  10. POJ 2566

    Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 1445   Accepted: 487   Spec ...