zoukankan      html  css  js  c++  java
  • hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722

    【题意】:

      找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNumbers,比如451就是一个4+5+1=10,求[A,B]之间这样的数的个数

     【题解】:

      先写一个暴力代码用来找规律

     发现: 0-10    1

        0-100  10

               0-1000   100

               0-990  99

        0-992  100

        0-997   100

      基本规律为 n/10 + (1或0)

      加1的情况为:n/10*10 到 n  有满足条件的  比如:997: 99 + (990到997是否有满足条件的,如果有则加1)

    【code】:

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    
    using namespace std;
    
    int isOne(__int64 n)  //例如:456计算450-456有没有符合条件的数
    {
        int s=0;
        __int64 i=n/10*10;
        __int64 m = n;
        for(;i<=m;i++)
        {
            n=i;
            s=0;
            while(n)
            {
                s+=n%10;
                n/=10;
            }
            if(s%10==0) return 1;
        }
        return 0;
    }
    
    __int64 getNum(__int64 n)
    {
        if(n<0) return 0;
        if(n<=10)   return 1;
        return n/10+isOne(n);
    }
    
    int main()
    {
        int t,cas=1;
        scanf("%d",&t);
        while(t--)
        {
            __int64 a,b;
            scanf("%I64d%I64d",&a,&b);
            printf("Case #%d: %I64d
    ",cas++,getNum(b)-getNum(a-1));
        }
        return 0;
    }
  • 相关阅读:
    Clustering by fast search and find of density peaks
    《第一行代码》(二)
    TF-IDF
    《第一行代码》(一)
    《OpenCV入门》(三)
    OpenCV入门(二)
    协方差矩阵特征向量的意义
    ICA
    整数划分
    1144. The Missing Number (20)
  • 原文地址:https://www.cnblogs.com/crazyapple/p/3315436.html
Copyright © 2011-2022 走看看