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_ ...
随机推荐
- 机器人学 —— 机器人感知(Gaussian Model)
机器人感知是UPNN机器人专项中的最后一门课程,其利用视觉方法来对环境进行感知.与之前提到的机器人视觉不同,机器人感知更侧重于对环境物体的识别与检测.与计算机视觉不同,机器人视觉所识别的物体往往不需要 ...
- 图像分类之特征学习ECCV-2010 Tutorial: Feature Learning for Image Classification
ECCV-2010 Tutorial: Feature Learning for Image Classification Organizers Kai Yu (NEC Laboratories Am ...
- How to write a product backlog step by step
一般来说,制定发布计划是在尝试回答这个问题:“最晚到什么时候为止,我们可以交付这个新系统的1.0版本“ 下面是验收标准规则的一个例子: 1. 所有重要性>=100的条目都必须在1.0版中发布. ...
- Flex 容器基本概念
申明文章出处:http://www.adobe.com/cn/devnet/flex/articles/flex-containers-tips.html Flex 4 容器可以提供一套默认的布局:B ...
- Ubuntu上安装Maven Eclipse以及配置
通过官方网站 http://maven.apache.org/download.cgi 下载到当前的maven安装包 ubuntu解压安装文件我用的是ubuntu 12.10版本的命令: ...
- Finalization
1.what is the main disadvantage of garbage collection? Typically, garbage collection has certain dis ...
- [HDOJ5584]LCM Walk(数论,规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5584 给一个坐标(ex, ey),问是由哪几个点走过来的.走的规则是x或者y加上他们的最小公倍数lcm ...
- 上下左右布局(DIV+CSS)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- create-maximum-number(难)
https://leetcode.com/problems/create-maximum-number/ 这道题目太难了,花了我很多时间.最后还是参考了别人的方法.还少加了个greater方法.很难. ...
- config windows virtual machine on mac
1.download virtualbox and related extension pack from http://www.oracle.com/technetwork/server-stor ...