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. The income statement

    The income statement measures performance over some period  of time,usually a quarter or a year.The ...

  2. C/C++求职宝典21个重点笔记

    转:http://blog.csdn.net/lanxuezaipiao/article/details/41557307 char c = '\72'; 中的\72代表一个字符,72是八进制数,代表 ...

  3. 用PHP向数据库中添加数据

    显示页面(用户可见) <body><form action="chuli.php" method="post">  //将该页面接收的数 ...

  4. bzoj 2141 线段树套平衡树

    用树套树来解决这个问题,存储每个节点的数值是多少,然后交换 对于答案的变更可以讨论下,假设交换的是x,y位置的数x<=y 如果x=y || high[x]=high[y]则对答案没有影响 如果h ...

  5. 设计模式 - Template Method

    今天下午主要研究了设计模式中的Template Method(模版方法设计模式). 在Spring中,对各种O/RM进行了封装,比如对Hibernate有HibernateTemplate封装:对JD ...

  6. share干什么的

    share到底干什么的 //--------------------打开GameServer,share中加载------------------------- .加载nBodyID //玩家的nBo ...

  7. CSS自定义文件上传按钮

    今天一同事问我文件上传按钮的问题,情况是这样的,他页面上有3个按钮,分为左中右三个,左边的位按钮甲,右边的位按钮乙,而中间的就是个文件选择按钮,情况大概是这个样子的: 两边的按钮都有了样式,但中间的选 ...

  8. JS数据类型的理解(猜测)

    Js 数据类型 对于这个主题,首先来看几个问题,如果你对这几个问题很清楚的话,那就请直接跳过吧,不用接着往下看了,如果不清楚,建议你还是看看. 1)如果判断函数?function 和object的联系 ...

  9. eclipse sdk 无法更新

    最近祖国越来越强了,强得android开发工具都没法更新了,但是祖国再怎么强也阻挡不了我开发的脚步.下面给大家分享个更新android sdk 的方法.方法原理就是利用国内镜像源. 工具/原料 电脑一 ...

  10. SEO优化的黑帽手法是否值得使用?

    PR劫持 可能很多人也会听到说,什么网站权重越高越好,这也就是后面越来越多人都对谷歌的PR的宣传看的很重,自建站的都追求PR值,权重越高代表这个网站越受信任. 比如一个新站PR值为0,一个老站PR为6 ...