这道题其实挺水,只是写的时候需要想清楚。我的方法是:

1.将[a,b]转化为[0,b+1)-[0,a)

2.预处理出非0的v在区间[0,10^p)出现次数以及0在区间[0,10^p)出现数

3.将一个区间再拆分为几段,如:

12345拆分为[0,10000),[10000,12000),[12000,12300),[12300,12340),[12340,12346)

下面是代码:

 #include<cstdio>
using namespace std ; static class digit {
long long pow10 [ ] ;
long long cnt [ ] ;
long long cnt0 [ ] ;
public :
digit () {
long long k = ;
for ( int i = ; i <= ; ++ i ) {
pow10 [ i ] = k ;
k *= ;
}
cnt0 [ ] = ;
for ( int i = ; i <= ; ++ i ) {
cnt [ i ] = pow10 [ i - ] + cnt [ i - ] * ;
//printf ( "%lld\n" , cnt [ i ] ) ;
cnt0 [ i ] = cnt [ i - ] * + cnt0 [ i - ] ;
//printf ( "%lld\n" , cnt0 [ i ] ) ;
}
}
long long operator () ( long long x , const int v ) {
x += ;
int w = - ; while ( pow10 [ ++ w ] < x ) ;
int c = ; long long ans = ;
if ( v == ) {
ans += cnt [ w ] * ( x / pow10 [ w ] - ) + cnt0 [ w ] ;
x %= pow10 [ w -- ] ;
}
while ( x ) {
ans += c * ( x / pow10 [ w ] * pow10 [ w ] ) + cnt [ w ] * ( x / pow10 [ w ] ) + ( x / pow10 [ w ] > v ? pow10 [ w ] : ) ;
c += ( x / pow10 [ w ] == v ) ;
x %= pow10 [ w -- ] ;
}
return ans ;
}
} DIGIT ; long long a , b ;
int main () {
scanf ( "%lld%lld" , & a , & b ) ;
printf ( "%lld" , DIGIT ( b , ) - DIGIT ( a - , ) ) ;
for ( int i = ; i < ; ++ i ) printf ( " %lld" , DIGIT ( b , i ) - DIGIT ( a - , i ) ) ;
putchar ( '\n' ) ;
return ;
}

bzoj1833 digit的更多相关文章

  1. [BZOJ1833][ZJOI2010]count 数字计数

    [BZOJ1833][ZJOI2010]count 数字计数 试题描述 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. 输入 输入文件中仅包含一行两个整数a ...

  2. bzoj1833: [ZJOI2010]count 数字计数 数位dp

    bzoj1833 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. O ...

  3. BZOJ1833 ZJOI2010 count 数字计数 【数位DP】

    BZOJ1833 ZJOI2010 count 数字计数 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包 ...

  4. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  5. [LeetCode] Number of Digit One 数字1的个数

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  6. [Leetcode] Number of Digit Ones

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  7. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  8. kaggle实战记录 =>Digit Recognizer

    date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...

  9. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

随机推荐

  1. RHEL7全新初始化进程管理systemd(图形启动和非图形启动切换)

    红帽RHEL7系统已经替换了大家熟悉的初始化进程System V init,正式采用全新的 初始化进程systemd.初始化进程systemd使用了并发启动机制,所以开机速度上得到了不小的 提升. 将 ...

  2. PowerDesigner15.1创建模型及生成带注释sql操作手册

    转自:http://blog.csdn.net/huiwenjie168/article/details/7824029 一.创建模型 操作:file-->new Model… 快捷键:ctrl ...

  3. 《c程序设计语言》读书笔记-十六位进制数转十进制

    #include <stdio.h> #include <stdio.h> int htoi(char s[]); main() { char s1[] = "10& ...

  4. 源码解析Android中View的measure量算过程

    Android中的Veiw从内存中到呈现在UI界面上需要依次经历三个阶段:量算 -> 布局 -> 绘图,关于View的量算.布局.绘图的总体机制可参见博文< Android中View ...

  5. leetcode:Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  6. HTML+CSS+JAVASCRIPT 总结

    1. HTML 1: <!doctype html> 2: <!-- This is a test html for html, css, javascript --> 3: ...

  7. 用FireMonkey写QQ皮肤

    这是运行在Windows平台的效果,同样不需要改一行代码就可以运行在Mac Os,并且效果完全相同: 用FireMonkey做界面速度非常快,其提供的Effect ,Filter,Animation等 ...

  8. jsp之jstl标签

    常用jstl标签 一.<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> ...

  9. [转]使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 事件详解

    在前文<使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础>中,Kayo 对 jQuery Mobile 事件的基 ...

  10. Linux C double linked for any data type

    /************************************************************************** * Linux C double linked ...