• ZOJ 2392 The Counting Problem(模拟)


    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368

    题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5,6,7,8,9的个数,例如从1024到1032有1024 1025 1026 1027 1028 1029 1030 1031 1032,其中10个0,10个1,7个2,3个3等等

    Sample Input

    1 10
    44 497
    346 542
    1199 1748
    1496 1403
    1004 503
    1714 190
    1317 854
    1976 494
    1001 1960
    0 0

    Sample Output

    1 2 1 1 1 1 1 1 1 1
    85 185 185 185 190 96 96 96 95 93
    40 40 40 93 136 82 40 40 40 40
    115 666 215 215 214 205 205 154 105 106
    16 113 19 20 114 20 20 19 19 16
    107 105 100 101 101 197 200 200 200 200
    413 1133 503 503 503 502 502 417 402 412
    196 512 186 104 87 93 97 97 142 196
    398 1375 398 398 405 499 499 495 488 471
    294 1256 296 296 296 296 287 286 286 247

    代码如下:

     1 # include<iostream>
     2 # include<cstdio>
     3 # include<cstring>
     4 # include<algorithm>
     5 # include<vector>
     6 using namespace std;
     7 
     8 int s,t;
     9 int res[10],dig[20],len;
    10 
    11 void solve(int num)
    12 {
    13     num ++;
    14     len =0;
    15     int temp =1;
    16     while(1)
    17     {
    18         dig[++len] = num%10;
    19         num /= 10;
    20         if(!num) break;
    21         temp *= 10;
    22     }
    23     for(int i=1; i<10; i++) res[i] += (len-1)*temp/10;
    24     res[0] += (len-1)*temp/10-(temp-1)/9;
    25     for(int i=1; i<dig[len]; i++)
    26     {
    27         res[i] += temp;
    28         for(int j=0; j<10; j++)
    29             res[j] += (len-1)*temp/10;
    30     }
    31     temp /= 10;
    32     for(int i=len-1; i>=1; i--)
    33     {
    34         for(int j=0; j<dig[i]; j++)
    35         {
    36             for(int k=len; k>i; k--)
    37                 res[dig[k]] += temp;
    38             res[j] += temp;
    39             for(int k=0; k<10; k++)
    40                 res[k] += (i-1)*temp/10;
    41         }
    42         temp /= 10;
    43     }
    44 }
    45 
    46 int main()
    47 {
    48     while(scanf("%d%d",&s,&t)&& s &&t)
    49     {
    50         memset(res,0,sizeof(res));
    51         if(s>t) swap(s,t);
    52         solve(s-1);
    53         for(int i=0; i<10; i++)
    54             res[i] = -res[i];
    55         solve(t);
    56         for(int i=0; i<9; i++)
    57             printf("%d ",res[i]);
    58         printf("%d
    ",res[9]);
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    Redis入门
    k8s dubbo微服务之maven配置
    NoSQL发展历史与阿里巴巴架构演进分析
    k8s交付dubbo微服务之部署Jenkins
    k8s版本平滑升级
    读 <The Lost Horizon> 感
    luogu P1026 统计单词个数
    acm一些小细节/技巧
    数据结构与算法——常用高级数据结构及其Java实现
    数据结构与算法——常用排序算法及其Java实现
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/3349690.html
Copyright © 2020-2023  润新知