[暑假集训--数位dp]LightOJ1140 How Many Zeroes?
Jimmy writes down the decimal representations of all natural numbers between and including m and n, (m ≤ n). How many zeroes will he write down?
Input
Input starts with an integer T (≤ 11000), denoting the number of test cases.
Each case contains two unsigned 32-bit integers m and n, (m ≤ n).
Output
For each case, print the case number and the number of zeroes written down by Jimmy.
Sample Input
5
10 11
100 200
0 500
1234567890 2345678901
0 4294967295
Sample Output
Case 1: 1
Case 2: 22
Case 3: 92
Case 4: 987654304
Case 5: 3825876150
问 l 到 r 出现了几个0
记一下出现了几个0,有没有前导零就好
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n,len,l,r;
LL f[][][][];
int d[];
int zhan[],top;
inline LL dfs(int now,int dat,int tot,int lead,int fp)
{
if (now==)return tot;
if (!fp&&f[now][dat][tot][lead]!=-)return f[now][dat][tot][lead];
LL ans=,mx=fp?d[now-]:;
for (int i=;i<=mx;i++)
{
int nexlead=lead&&i==&&now-!=;
ans+=dfs(now-,i,tot+(i==&&!nexlead),nexlead,fp&&i==d[now-]);
}
if (!fp)f[now][dat][tot][lead]=ans;
return ans;
}
inline LL calc(LL x)
{
if (x<=)return x+;
LL xxx=x;
len=;
while (xxx)
{
d[++len]=xxx%;
xxx/=;
}
LL sum=;
for (int i=;i<=d[len];i++)
{
if (i)sum+=dfs(len,i,,,i==d[len]);
else sum+=dfs(len,,len==,,!d[len]);
}
return sum;
}
main()
{
int T=read(),cnt=;
while (T--)
{
l=read();r=read();
if (r<l)swap(l,r);
memset(f,-,sizeof(f));
printf("Case %d: %lld\n",++cnt,calc(r)-calc(l-));
}
}
LightOJ 1140
[暑假集训--数位dp]LightOJ1140 How Many Zeroes?的更多相关文章
- [暑假集训--数位dp]LightOj1205 Palindromic Numbers
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
- [暑假集训--数位dp]hdu3709 Balanced Number
A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...
- [暑假集训--数位dp]hdu3555 Bomb
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...
- [暑假集训--数位dp]hdu2089 不要62
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...
- [暑假集训--数位dp]hdu5787 K-wolf Number
Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...
- [暑假集训--数位dp]UESTC250 windy数
windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Inp ...
- [暑假集训--数位dp]LightOj1032 Fast Bit Calculations
A bit is a binary digit, taking a logical value of either 1 or 0 (also referred to as "true&quo ...
- [暑假集训--数位dp]hdu5898 odd-even number
For a number,if the length of continuous odd digits is even and the length of continuous even digits ...
随机推荐
- nfs-ganesha使用
一 nfs-ganesha在centos7上安装 yum -y install centos-release-gluster yum install -y nfs-ganesha.x86_64yum ...
- 小试牛刀,建立jsp网页与导出war包
一.建立jsp网页 首先创建一个动态项目(我们学习的是动态网) 二.检查编码utf-8有没错误. 如有错误就是没有设置eclipse,请按照eclipse设置 编写一段代码,进行了解 三.导出一个wa ...
- 【数学 技巧】divisor
没考虑重复lcm处理被卡TLE没A真是可惜 题目大意 $n$为$k-可表达的$当且仅当数$n$能被表示成$n$的$k$个因子之和,其中$k$个因子允许相等. 求$[A,B]$之间$k-可表达$的数的个 ...
- 【AC自动机】bzoj4327: JSOI2012 玄武密码
题目思路没话讲:主要是做题时候的细节和经验 Description 在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河.相传一日,一缕紫气从天而至,只一瞬间便消失在了进香河中 ...
- Golang tcp转发 remoteAddr错误
Golang tcp 转发 第一版本 accept获取的Conn里的localAddr做为源地址,remoteAddr来做为目的地址 // tcpForward package main import ...
- 【mysql】The server quit without updating PID file
groupadd mysql useradd -r -g mysql mysql cd /usr/local/mysql chown -R mysql:mysql . scripts/mysql_ ...
- selenium+phantomjs爬取bilibili
selenium+phantomjs爬取bilibili 首先我们要下载phantomjs 你可以到 http://phantomjs.org/download.html 这里去下载 下载完之后解压到 ...
- R-data.table
data.table可以扩展和增强data.frame的功能,在分组操作和组合时访问速度更快. require(data.table) theDT = data.table(A=1:10, B=let ...
- POJ:2695-The Pilots Brothers' refrigerator
题目链接:http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limi ...
- 思维水题:UVa512-Spreadsheet Tracking
Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...