uva11038_How Many O's?_数位DP
问m~n之间的数中共有多少个0,过程稍稍麻烦了一些,半天的时间才搞定。
直接上码吧
/*************************************************************************
> File Name: 11038_数位DP.cpp
> Author: Chierush
> Mail: qinxiaojie1@gmail.com
> Created Time: 2013年06月16日 星期日 16时13分54秒
************************************************************************/ #include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm> #define LL long long
#define LLU unsigned long long using namespace std; LL g(char *s)
{
LL ans=0;
for (int i=1;i<strlen(s);++i)
ans=ans*10+s[i]-'0';
return ++ans;
} LL f[12],Count[12],sum[12],sbit[12];
char s[12]; LL dp(LL n)
{
if (n<0) return 0;
if (n<10) return 1;
LL ans=0;
sprintf(s,"%lld",n);
ans+=sum[strlen(s)-1]+(s[0]-'1')*(sum[strlen(s)-1]+sbit[strlen(s)-1]);
//printf("---%lld\n",ans);
for (int i=1;i<strlen(s)-1;++i)
if (s[i]>'0')
{
ans+=(sum[strlen(s)-i-1]+sbit[strlen(s)-i-1])*(s[i]-'1');
ans+=Count[strlen(s)-i-1]+sum[strlen(s)-i-1]+sbit[strlen(s)-i-1];
}
else
ans+=g(s+i);
return ++ans;
} int main()
{
Count[1]=10;
for (int i=2;i<=10;++i)
Count[i]=Count[i-1]*10;
for (int i=2;i<=10;++i)
sbit[i]=Count[i-1]+sbit[i-1];
sum[1]=f[1]=1;
for (int i=2;i<=10;++i)
f[i]=9*(sum[i-1]+sbit[i-1]),sum[i]=sum[i-1]+f[i];
LL n,m;
//printf("%lld\n",dp(500));
while (scanf("%lld%lld",&m,&n) && m>=0)
printf("%lld\n",dp(n)-dp(m-1));
return 0;
}
uva11038_How Many O's?_数位DP的更多相关文章
- BZOJ_1662_[Usaco2006 Nov]Round Numbers 圆环数_数位DP
BZOJ_1662_[Usaco2006 Nov]Round Numbers 圆环数_数位DP Description 正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺 ...
- BZOJ_1833_[ZJOI2010]count 数字计数_数位DP
BZOJ_1833_[ZJOI2010]count 数字计数_数位DP 题意: 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. 分析: 数位DP f[i][ ...
- BZOJ_1026_[SCOI2009]windy数_数位DP
BZOJ_1026_[SCOI2009]windy数_数位DP 题意:windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之 ...
- BZOJ_1833_[ZJOI2010]_数字计数_(数位dp)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1833 统计\(a~b\)中数字\(0,1,2,...,9\)分别出现了多少次. 分析 数位dp ...
- [bzoj1026][SCOI2009]windy数_数位dp
windy数 bzoj-1026 题目大意:求一段区间中的windy数个数. 注释:如果一个数任意相邻两位的差的绝对值都不小于2,这个数就是windy数,没有前导0.$区间边界<=2\cdot ...
- [bzoj3209]花神的数论题_数位dp
花神的数论题 bzoj-3209 题目大意:sum(i)表示i的二进制表示中1的个数,求$\prod\limits_{i=1}^n sum(i)$ 注释:$1\le n\le 10^{15}$. 想法 ...
- [bzoj3530][Sdoi2014]数数_AC自动机_数位dp
数数 bzoj-3530 Sdoi-2014 题目大意:给你一个整数集合,求所有不超过n的正整数,是的它的十进制表示下不能再一段等于集合中的任意数. 注释:$1\le n \le 1200$,$1\l ...
- BZOJ_1026_[SCOI2009]_windy数_(数位dp)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1026 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为wi ...
- [Comet OJ - Contest #4 D][39D 1584]求和_"数位dp"
求和 题目大意: 数据范围: 题解: 脑筋急转弯可还行..... 我们发现只需要最后枚举个位/xk/xk 因为前面的贡献都是确定的了. 故此我们最后暴力统计一下就好咯. 不知道为啥我组合数一直过不去, ...
随机推荐
- PLC中ST语言的几种程序流程控制语句
ST语言是IEC61131-3中规定的5中标准语言之一,目前常用见品牌的PLC都支持这种语言(施耐德,AB可以直接选择创建该类型的程序段或者功能块,西门子的略微麻烦一点),ST语言的一个好处是移植性好 ...
- Information centric network (icn) node based on switch and network process using the node
The present invention relates to an apparatus for supporting information centric networking. An info ...
- “warning C4996: 'fopen': This function or variable may be unsafe”和“LINK : fatal error LNK1104”的解决办法
程序有时编译出现警告C4996,报错: warning C4996: 'fopen': This function or variable may be unsafe. Consider using ...
- 矩阵十点【两】 poj 1575 Tr A poj 3233 Matrix Power Series
poj 1575 Tr A 主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 题目大意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的 ...
- 还在使用vc6.0吗??vs2010吧
每个人在面对新的事物的时候,总是充满了排斥感,当vista和win7来临的时候,我们还在留恋xp,说xp是如何的好,win7是如何的不给力,当然,我们必须承认,xp是一款优秀的操作系统,这个我们无法否 ...
- python3使用Lxml库操作XPath
download address: http://pypi.python.org/pypi/lxml/2.3 lxml is a Pythonic, mature binding for the li ...
- NYOJ781 又见回文数
又见回文数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 冷淡的回文数被水了,各种被水,然后他非常生气,然后... 一个数从左边读和从右边读一样,就说这个数是回文数 ...
- NS2网络模拟(3)-吞吐率
1: #NS2_有线部分\Throughput.awk 2: 3: BEGIN { 4: #Initialize the variable 5: init = 0; 6: i = 0; 7: } 8: ...
- PO、VO、BO、DTO、POJO、DAO之间的关系
J2EE开发中大量的专业缩略语很是让人迷惑,尤其是跟一些高手讨论问题的时候,三分钟就被人家满口的专业术语喷晕了,PO VO BO DTO POJO DAO,一大堆的就来了(听过老罗对这种现象的批判的朋 ...
- 图形化界面安装oracle报错Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set.
问题描述: 在Linux + oracle 安装时,采有root 帐号登录x-windows 界面,然后 $su oracle 登录录安装Oracle 报以下错误: >>> Coul ...