[暑假集训--数位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,有没有前导零就好

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 using namespace std;
18 inline LL read()
19 {
20     LL x=0,f=1;char ch=getchar();
21     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
22     while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
23     return x*f;
24 }
25 LL n,len,l,r;
26 LL f[20][20][20][2];
27 int d[110];
28 int zhan[20],top;
29 inline LL dfs(int now,int dat,int tot,int lead,int fp)
30 {
31     if (now==1)return tot;
32     if (!fp&&f[now][dat][tot][lead]!=-1)return f[now][dat][tot][lead];
33     LL ans=0,mx=fp?d[now-1]:9;
34     for (int i=0;i<=mx;i++)
35     {
36         int nexlead=lead&&i==0&&now-1!=1;
37         ans+=dfs(now-1,i,tot+(i==0&&!nexlead),nexlead,fp&&i==d[now-1]);
38     }
39     if (!fp)f[now][dat][tot][lead]=ans;
40     return ans;
41 }
42 inline LL calc(LL x)
43 {
44     if (x<=0)return x+1;
45     LL xxx=x;
46     len=0;
47     while (xxx)
48     {
49         d[++len]=xxx%10;
50         xxx/=10;
51     }
52     LL sum=0;
53     for (int i=0;i<=d[len];i++)
54     {
55         if (i)sum+=dfs(len,i,0,0,i==d[len]);
56         else sum+=dfs(len,0,len==1,1,!d[len]);
57     }
58     return sum;
59 }
60 main()
61 {
62     int T=read(),cnt=0;
63     while (T--)
64     {
65         l=read();r=read();
66         if (r<l)swap(l,r);
67         memset(f,-1,sizeof(f));
68         printf("Case %d: %lld\n",++cnt,calc(r)-calc(l-1));
69     }
70 }

LightOJ 1140

时间: 2024-08-25 00:13:12

[暑假集训--数位dp]LightOJ1140 How Many Zeroes?的相关文章

[暑假集训--数位dp]hdu3652 B-number

A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb

[暑假集训--数位dp]LightOj1205 Palindromic Numbers

A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this problem you will be given two integers i j, you have to find the number of palindromic numbers between i and j

[暑假集训--数位dp]hdu5898 odd-even number

For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even number between L,R(1<=L<=R<= 9*10^18). Input First line a t,then t c

[暑假集训--数位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" or "false" respectively). And every decimal number has a binary representation which is actually a series of bits. If a bit of a number is 1 a

[暑假集训--数位dp]cf55D Beautiful numbers

Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful num

[暑假集训--数位dp]hdu5787 K-wolf Number

Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation of x is pairwised different. Given (L,R,K), please count how many K-wolf numbers in range of L,RL,R . Input The input contains multiple test cases. The

[暑假集训--数位dp]UESTC250 windy数

windy定义了一种windy数. 不含前导零且相邻两个数字之差至少为22 的正整数被称为windy数. windy想知道,在AA 和BB 之间,包括AA 和BB ,总共有多少个windy数? Input 包含两个整数,AA BB . 满足 1≤A≤B≤20000000001≤A≤B≤2000000000 . OutputSample Input 1 10 Sample Output 9 记一下上一位出现的数是啥 1 #include<cstdio> 2 #include<iostrea

UVa 12683 Odd and Even Zeroes(数论+数位DP)

题意: 问 小于等于n的数中 (0<=n <= 1e18)有多少个的阶乘的尾数0的个数为偶数 思路:暴力肯定不行,那么从数论出发,要使尾数0的个数为偶数,那么就要使N的阶乘5的幂为偶数,(二的指数肯定小于等于5的指数),求N!的阶乘5的指数就是N/5+ N/25+N/125.... 以530为例,尝试着将转化为5进制  即为 4110,那么5的指数 就是 411+41+4 (5进制)容易发现要使这个数是偶数,就是要使5进制奇数位的个数为偶数,根据刚才那个加法,可以看出,最后结果的5进制的末位就

暑假集训总结

总结这一个暑假呐,就是被DP虐哭了的一个月,这TM就是一门玄学,没有一定的脑洞,怎么可能学好DP,用抽象的思维将一个大问题拆分成多个阶段决策问题,然后表示每个阶段的状态,再在每个状态之间进行决策的选择.题做多了之后才发现,DP的过程其实就是将状态你前面记录的过程记忆下来,然后后面你进行决策的时候以这个决策为依据进行决策. 初来的那几天 7.21就来学校,一个月的期末复习把以前学的知识忘了不少,来的几天先把以前的题做了一遍,把以前的知识点捡起来,以前做的急没来得及消化,现在又有了很多很深刻理解.话