bzoj1833 digit
这道题其实挺水,只是写的时候需要想清楚。我的方法是:
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的更多相关文章
- [BZOJ1833][ZJOI2010]count 数字计数
[BZOJ1833][ZJOI2010]count 数字计数 试题描述 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. 输入 输入文件中仅包含一行两个整数a ...
- bzoj1833: [ZJOI2010]count 数字计数 数位dp
bzoj1833 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. O ...
- BZOJ1833 ZJOI2010 count 数字计数 【数位DP】
BZOJ1833 ZJOI2010 count 数字计数 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包 ...
- [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 ...
- [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 ...
- [Leetcode] Number of Digit Ones
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...
- 【Codeforces715C&716E】Digit Tree 数学 + 点分治
C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...
- kaggle实战记录 =>Digit Recognizer
date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...
- [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_ ...
随机推荐
- 生成n对括号的所有合法排列
实例 n = 3,所有的合法序列 ((())) (()()) (())() ()(()) ()()() 思路 针对一个长度为2n的合法排列,第1到2n个位置都满足如下规则 左括号的个数≥右括号的个数 ...
- libevent 定时器timer
libevent是一个基于事件触发的网络库,memcached底层也是使用libevent库. 总体来说,libevent有下面一些特点和优势:* 事件驱动,高性能:* 轻量级,专注于网络: * 跨平 ...
- java 无法找到main类解决办法
java 无法找到main类解决办法 如果Java类有包名,你必须建相应的包文件夹并把文件编译或拷贝到到相应的文件夹下: 如下: 1.源文件文件: E:\test\src\tes ...
- PHP的面向对象编程
面向对象编程的概念: 不同的作者之间说法可能不一样,但是一个OOP语言必须有以下几方面: 抽象数据类型和信息封装 继承 多态 在PHP中是通过类来完成封装的: <?php class Somet ...
- Scorm 1.2 开发文档
原文出处 电华教育研究杂志2010年第7期<SCORM标准学习跟踪机制的研究与实现> http://blog.sina.com.cn/s/blog_964ec55001014nl0.htm ...
- 用任务管理器画CPU正弦曲线
这个最初是在microsoft的<编程之美>中看到的,用你的程序来控制CPU的使用率. 首先是要求写一个用来实现CPU使用率为50%程序. 这个还是很好实现的,只要让你的程序忙的时间课空闲 ...
- MVC用户登陆验证及权限检查(Form认证)
1.配置Web.conf,使用Form认证方式 <system.web> <authentication mode="None" /> ...
- 了解ThinkPHP(一)
1.项目开发,中,会遇到的问题: 1). 多人开发项目,分工不合理,(html php mysql) 2). 代码风格不一样,后期维护十分困难 3). 项目生命周期十分短,项目生命没有延续性, ...
- iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
原文: http://blog.csdn.net/songrotek/article/details/8692866?utm_source=tuicool 对于UIToolbar,UINavigat ...
- 报错:对象必须实现 IConvertible;以分隔符进行分割链接concat_ws的使用方法;mysql数据类型转换cast,convert
错误故障,mysql 服务器上用 concat_ws 函数,连接了一串数字,最后 服务器返回的字段就变成了一个 byte ,而我们想要的类型是 string 类型,那么转换的时候,就报错了. 正确 ...