[暑假集训--数位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 ...
随机推荐
- 怎么在WEBSTORM中设置代码模板 Live Templates
怎么在WEBSTORM中设置代码模板 Live Templates setting 里面 https://www.cnblogs.com/xinzaimengzai/p/9938464.html
- BCB:WebBrowser 控件说明
控件文件:system32\shdocvw.oca shdocvw.dll 注册:regsvr32 shdocvw.dll WebBrowser 是 IE 内核做的 VB 控件, WebBrow ...
- JavaScript深入浅出第2课:函数是一等公民是什么意思呢?
摘要: 听起来很炫酷的一等公民是啥? <JavaScript深入浅出>系列: JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函 ...
- c#List结合IEqualityComparer求交集
List元素类: public class MultiPointSearchingRet { public int ID { get; set; } public string PlateNumber ...
- 解决AjaxFileUpload中文化/国际化的问题。
由微软官方提供的AjaxControlToolKit,在ASP.NET开发过程中,确实能够给开发者带来很多的便利,节约开发者的重复劳动.这套控件也是比较成熟的,在性能方面也不会太差,至少能够满足一般开 ...
- 【Python学习之七】递归——汉诺塔问题的算法理解
汉诺塔问题 汉诺塔的移动可以用递归函数非常简单地实现.请编写move(n, a, b, c)函数,它接收参数n,表示3个柱子A.B.C中第1个柱子A的盘子数量,然后打印出把所有盘子从A借助B移动到C的 ...
- GoF23种设计模式之结构型模式之组合模式
一.概述 将对象组合成树型结构以表示“部分--整体”的层次关系.组合模式使得用户对单个对象和组合对象的使用具有一致性. 二.适用性 1.你想表示对象的部分--整体层次结构的时候. 2.你希望用户忽略组 ...
- navigationcontroller和navigationbar和navigationitem之间的区别以及不用nib实现点击屏幕关闭虚拟键盘20130911
1.UIViewController UIView的关系. UIView是视图,UIViewController是视图控制器,两者之间是从属关系,当创建一个UIViewController的时候,一般 ...
- Ice cream samples Gym - 101670G 滑动扫描
题目:题目链接 思路:比赛中读错了题,题目要求选一个连续区间,却读成了随便选取几个柜台,英语要好好学啊,读懂题就很简单了,扫一遍就出结果了 AC代码: #include <iostream> ...
- poj 3616 奶牛产奶问题 dp算法
题意:奶牛产奶,农夫有m个时间段可以挤奶,在工作时间 f t 内产奶量为m,每次挤完奶后,奶牛需要休息R.问:怎么安排使得产奶量最大? 思路:区间dp dp[i]表示第i个时段 对农夫工作的结束时间 ...