所以。。。大家说的LOJ到底是LightOJ还是LibreOJ?= =!

终于有道比较清爽的数位DP题了。。虽然写得依旧很慢就是。。qaq

统计0的个数。。。这个需要稍微分一下是不是前导0,标记一下前面有没有非0数即可,然后。。就是在统计数的个数时太想当然了。。以为是10^n什么的。。计算上界的时候可不是这样的耶。。所以要边转移边统计。。

用cin的原因是。。。用%llu输入时编译器不造为什么有warning。。。还是菜蛙qaq




#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define eps 1e-8
#define inf 1000000007
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define ls T[i<<1]
#define rs T[i<<1|1]
#define op T[i]
#define mid (x+y>>1)
#define NM 20
#define nm 10005
#define pi 3.141592653
using namespace std;
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}


int n,b[NM];
unsigned ll d[NM][2],c[NM],_x,_y;
unsigned ll dfs(int i,bool f,bool f1){
if(!i)return 0;
if(!f&&d[i][f1])return d[i][f1];
int m=f?b[i]:9;unsigned ll ans=0,s=0;
inc(j,0,m)if(j==0&&f1)ans+=dfs(i-1,f&&j==m,f1),ans+=c[i-1],s+=c[i-1];
else ans+=dfs(i-1,f&&j==m,f1||j>0),s+=c[i-1];
c[i]=s;
return d[i][f1]=ans;
}

unsigned ll solve(unsigned ll x){
n=0;mem(d);mem(b);
for(unsigned ll t=x;t;t/=10)b[++n]=t%10;
return dfs(n,1,0)+1;
}

int main(){
//freopen("data.in","r",stdin);
c[0]=1;
int _=read();
inc(T,1,_){
cin>>_x>>_y;
unsigned ll t=solve(_y);if(_x>0)t-=solve(_x-1);
printf("Case %d: %llu\n",T,/*solve(_y)-solve(_x-1)*/t);
}
return 0;
}




1140 - How Many Zeroes?


​​

​​  ​



​PDF (English) ​

​Statistics ​

​Forum ​


Time Limit: 2 second(s)

Memory Limit: 32 MB


Jimmy writes down the decimal representations of all naturalnumbers between and including m and n, (m ≤ n). How many zeroeswill 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 andn, (m ≤ n).

Output

For each case, print the case number and the number of zeroeswritten down by Jimmy.

Sample Input

Output for Sample Input

5

10 11

100 200

0 500

1234567890 2345678901

0 4294967295

Case 1: 1

Case 2: 22

Case 3: 92

Case 4: 987654304

Case 5: 3825876150

 



Special Thanks: Jane Alam Jan (Description, Solution, Dataset)