标签:
30%的数据中,a<=b<=10^6;
100%的数据中,a<=b<=10^12。
#include<bits/stdc++.h> #define ll long long using namespace std; ll ans[10],m[15],ansb[10]; ll a,b; inline void work(ll x) { char s[15]; int ss[15]; sprintf(s+1,"%lld",x); int len=strlen(s+1); for (int i=1;i<=len;i++) ss[i]=s[len-i+1]-‘0‘; for (int i=len;i>0;i--) { for (int j=0;j<=9;j++) ans[j]+=m[i-1]*(i-1)*ss[i]; for (int j=0;j<ss[i];j++) ans[j]+=m[i]; ans[ss[i]]+=x%m[i]+1; } for (int i=2;i<=len;i++) ans[0]-=m[i]; } int main() { m[1]=1; for (int i=2;i<=15;i++) m[i]=m[i-1]*10; scanf("%lld%lld",&a,&b); work(b); for (int i=0;i<=9;i++) ansb[i]=ans[i]; memset(ans,0,sizeof(ans)); work(a-1); for (int i=0;i<=8;i++) printf("%lld ",ansb[i]-ans[i]); printf("%lld",ansb[9]-ans[9]); return 0; }
[ZJOI2010][BZOJ1833] count 数字计数|模拟
标签:
原文地址:http://www.cnblogs.com/ws-fqk/p/4765890.html