tkj
文章143
标签102
分类0
bzoj 1833: [ZJOI2010]count 数字计数

bzoj 1833: [ZJOI2010]count 数字计数

.

做了好久。。。
代码:

#include<bits/stdc++.h>
using namespace std;

long long f[15], f0[15], a, b, ans1[10], ans2[10], Pow[15];

void wk(long long x, long long *ans)
{
    vector<int>g;
    long long hh = x;
    while (hh)
    {
        g.push_back(hh % 10);
        hh /= 10;
    }
    int n = g.size()-1;
    for (int i = 1; i <= 9; i++)
        ans[i] = f[n];
    for (int i = n; i > 0; i--)
        ans[0] += f0[i];
    for (int i = n; i >= 0; i--)
    {
        if (g[i])
        {
            for (int j = 0; j <= 9; j++)
                ans[j] += f[i] * (g[i] - 1);
            // ans[0] += f0[i] * (g[i] - 1);
        }
        for (int j = 1; j < g[i]; j++)
            ans[j] += Pow[i];
        if (i != n && g[i])
        {
            ans[0] += Pow[i];
            for (int j = 0; j <= 9; j++)
                ans[j] += f[i];
        }
        ans[g[i]] += x % Pow[i];
    }
    if (x)
        ans[0]++;
}
int main()
{
    scanf("%lld%lld", &a, &b);
    Pow[0] = 1;
    Pow[1] = 10;
    f0[1] = 0;
    f[1] = 1;
    for (int i = 2; i <= 12; i++)
    {
        f0[i] = f0[i-1] * 10 + Pow[i-1]-Pow[i-2];
        f[i] = f[i-1] * 10 + Pow[i-1];
        Pow[i] = Pow[i-1] * 10;
    }/*
    for (int i = 1; i <= 12; i++)
        printf("%lld %lld\n", f[i], f0[i]);
    puts("\n");*/
    wk(a, ans1);
    wk(b+1, ans2);
    for (int i = 0; i < 9; i++)
        printf("%lld ", ans2[i] - ans1[i]);
    printf("%lld\n", ans2[9] - ans1[9]);
}
本文作者:tkj
本文链接:https://tkj666.github.io/28/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可