BZOJ P1833 LOJ #10169. 「ZJOI2010」数字计数【数位DP】

现在看来比较简单了:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,x,y) for(ll i=(x);i<=(y);i++)
#define repd(i,x,y) for(ll i=(x);i>=(y);i--)

using namespace std;

const ll N=1e2+5;

ll a,b,w[N],cnt[N],ansa[N],ansb[N];

void getcnt(ll lim,ll *ans) {
    w[0]=0;
    while(lim) {
        w[++w[0]]=lim%10;lim/=10;
    }
    
    repd(i,w[0],1) {
        rep(j,0,9) ans[j]+=cnt[i-1]*w[i];
        rep(j,0,w[i]-1) ans[j]+=pow(10,i-1);
        ll tmp=0;
        repd(j,i-1,1) tmp=tmp*10+w[j];
        ans[w[i]]+=tmp+1;ans[0]-=pow(10,i-1);
    }
}

int main() {
    scanf("%lld%lld",&a,&b);
 
    cnt[1]=1;
    rep(i,2,12) cnt[i]=cnt[i-1]*10+pow(10,i-1);
    
    getcnt(b,ansb);
    getcnt(a-1,ansa);
    
    rep(i,0,9) {
        printf("%lld ",ansb[i]-ansa[i]);
    }
}

猜你喜欢

转载自blog.csdn.net/yanzhenhuai/article/details/82831777