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. MySQL数据库远程连接开启方法

    有时候需要远程连接mysql数据库,默认是不可以的,可以参考下面的方法,解决下. 1.登陆自己机器的MySQL数据库:mysql -uroot -p密码 设置root用户可以任意IP访问,代码如下(可 ...

  2. footer居底

    结构部分: <div class="container"> <div class="header">header</div> ...

  3. 【CentOS】Eclipse中svn插件使用

    目录: 1.安装 2.使用 3.错误 1.安装 svn插件地址: Subclipse 1.6.x Update Site - http://subclipse.tigris.org/update_1. ...

  4. bzoj 2821 分块处理

    大题思路就是分块,将n个数分成sqrt(n)个块,然后 处理出一个w数组,w[i,j]代表第i个块到第j个块的答案 那么对于每组询问l,r如果l,r在同一个块中,直接暴力做就行了 如果不在同一个块中, ...

  5. 全球SEO行业调查报告

    这是一份来自MOZ的调查报告,本报告是两年一次的SEO行业调查,主要围绕SEO从业人员的特征.工作内容时间分配比例.对未来市场的看法.使用的seo工具以及SEO知识扩充渠道等展开. 这份报告可以对从事 ...

  6. Metasploit Framework命令汇总

    一.msfconsole ? 帮助菜单back 从当前环境返回banner 显示一个MSF bannercd 切换目录color 颜色转换connect 连接一个主机exit 退出MSFhelp 帮助 ...

  7. uialertview 改变文字显示位置

    - (void)willPresentAlertView:(UIAlertView *)alertView{ UIView * view = [alertView.subviews objectAtI ...

  8. Sqli-labs less 37

    Less-37 本关与34关是大致相似的,区别在于处理post内容用的是mysql_real_escape_string()函数,而不是addslashes()函数,但是原理是一直的,上面我们已经分析 ...

  9. iOS第三方支付-银联支付

    #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "UPPayPluginDeleg ...

  10. Android线程消息通信(一)

    Android在Java标准线程模型的基础上,提供了消息驱动机制,用于多线程之间的通信.基于消息驱动机制的线程通信模型陈伟线程消息通信.在标准线程模型中,线程执行完毕后便退出,而Android扩展了线 ...