• HDU 4722 数位dp


    Good Numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4753    Accepted Submission(s): 1511


    Problem Description
    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
    You are required to count the number of good numbers in the range from A to B, inclusive.
     
    Input
    The first line has a number T (T <= 10000) , indicating the number of test cases.
    Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
     
    Output
    For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
     
    Sample Input
    2
    1 10
    1 20
     
    Sample Output
    Case #1: 0
    Case #2: 1
    Hint
    The answer maybe very large, we recommend you to use long long instead of int.
     
    Source
     题意:对一个数字 每一位求和%10==0 问一个区间内有多少个这类数字
     题解:模板题
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 #include <stack>
     7 #include <queue>
     8 #include <cmath>
     9 #include <map>
    10 #define ll  __int64
    11 #define dazhi 2147483647
    12 #define bug() printf("!!!!!!!")
    13 #define M 200005
    14 using namespace  std;
    15 int t;
    16 ll l,r;
    17 ll bit[20];
    18 ll dp[100][15];
    19 ll functi(int pos ,int flag,int m)
    20 {
    21     if(pos==0) return (m==0);
    22     if(flag&&dp[pos][m]!=-1) return dp[pos][m];
    23     ll x=flag?9:bit[pos];
    24     ll ans=0;
    25     for(ll i=0;i<=x;i++)
    26         ans+=functi(pos-1,flag||i<x,(m+i)%10);
    27     if(flag) dp[pos][m]=ans;
    28     return ans;
    29 }
    30 ll fun(ll num)
    31 {
    32     int len=0;
    33     memset(bit,0,sizeof(bit));
    34     while(num)
    35     {
    36         bit[++len]=num%10;
    37         num/=10;
    38     }
    39     return functi(len,0,0);
    40 }
    41 int main()
    42 {
    43     while(scanf("%d",&t)!=EOF)
    44     {
    45         memset(dp,-1,sizeof(dp));
    46          for(int i=1;i<=t;i++)
    47          {
    48              scanf("%I64d %I64d",&l,&r);
    49              printf("Case #%d: %I64d
    ",i,fun(r)-fun(l-1));
    50          }
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    服务器并发由200到4000并发的一个优化
    HTTP之一 If-Modified-Since & If-None-Match
    HTTP之二 http 301 和 302的区别
    003_内存的深入理解
    002_IO磁盘深入理解
    django学习笔记【003】创建第一个带有model的app
    MySQL innodb_autoinc_lock_mode 详解
    django学习笔记【002】创建第一个django app
    django学习笔记【001】django版本的确定&创建一个django工程
    innodb引擎redo文件维护
  • 原文地址:https://www.cnblogs.com/hsd-/p/6613500.html
Copyright © 2020-2023  润新知