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_ ...
随机推荐
- log log4net用代码记录日志
log4net 用代码记录日志 今天在开发项目的时候,遇到跨域调用log4net中的类,出现了一个bug,提示LogImpl未标记可序列化,此时,我靠,麻烦了,这个类又不是咱们自己的,改源码我想应该 ...
- C#服务启动以及服务指令
Windows系统中使用 cmd 命令安装和卸载服务方法如下: 第一种方法: 1. 开始->运行->cmd 2. cd到C:\WINDOWS\Microsoft.NET\Framework ...
- 压缩工具类 - ZipUtils.java
压缩工具类,提供压缩文件.解压文件的方法. 源码如下:(点击下载 - ZipUtils.java .FolderUtils.java.ant-1.7.0.jar.commons-io-2.4.jar. ...
- poj - 3225 Roadblocks(次短路)
http://poj.org/problem?id=3255 bessie 有时会去拜访她的朋友,但是她不想走最快回家的那条路,而是想走一条比最短的路长的次短路. 城镇由R条双向路组成,有N个路口.标 ...
- Hosting Your Own NuGet Feeds
Hosting Your Own NuGet Feeds Hosting the NuGet Gallery Locally in IIS https://github.com/NuGet/NuGet ...
- 谈谈 char *num="123";和char num[4]="123";的区别
最近写程序的时候发现这样一个问题 #include<iostream> #include <string.h> using namespace std; void revers ...
- 微信朋友圈如何同时分享(图片+文字) Android版
以下是:微信朋友圈SDK 分享图片的代码,但只能分享图片,不能分享文字,如何才能图片和文字同时分享?求各位大神指教! public class MainActivity extends Activit ...
- HDu 3449 (有依赖的01背包) Consumer
题意: 有n件物品,对应有不同的价格和价值,这是典型的01背包.但现在有了一个限制,要买物品先买能装这件物品的特定的盒子,盒子的价值为0 代码理解得还不是太好,感觉这是一个“二重”的01背包.首先假设 ...
- 属性readwrite,readonly,assign,retain,copy,nonatomic
copy:建立一个索引计数为1的对象,然后释放旧对象 对NSString对NSString 它指出,在赋值时使用传入值的一份拷贝.拷贝工作由copy方法执行,此属性只对那些实行了NSCopying协议 ...
- BZOJ 3306 树
dfs序建线段树+分类讨论+写的有点长. #include<iostream> #include<cstdio> #include<cstring> #includ ...