zoukankan      html  css  js  c++  java
  • HDU_2212_水

    DFS

    Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 7486    Accepted Submission(s): 4578


    Problem Description
    A DFS(digital factorial sum) number is found by summing the factorial of every digit of a positive integer. 

    For example ,consider the positive integer 145 = 1!+4!+5!, so it's a DFS number.

    Now you should find out all the DFS numbers in the range of int( [1, 2147483647] ).

    There is no input for this problem. Output all the DFS numbers in increasing order. The first 2 lines of the output are shown below.
     
    Input
    no input
     
    Output
    Output all the DFS number in increasing order.
     
    Sample Output
    1 2 ......
     
    所说最后觉得挺水的,但一来看见 [1, 2147483647] 就在想什么比较好的方法可以处理,结果想了半天也没想出来。一看题解,9!=3628801,也就是说10个9也就是36288010,1e7的复杂度,加上中间对每个位的处理,也就是不到1e8的复杂度,而题目给了2000ms,所以可以解决。
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int mul[10];
    
    void calcu()
    {
        mul[0]=1;
        for(int i=1;i<=9;i++)
            mul[i]=mul[i-1]*i;
    }
    
    bool cmp(int x)
    {
        int a,tem=0;
        a=x;
        do
        {
            int mm=a%10;
            tem+=mul[mm];
            a/=10;
        }while(a>0);
        if(x==tem)
            return 1;
        else
            return 0;
    }
    
    int main()
    {
        long long num1=0,num2=0;
        calcu();
        //cout<<mul[9];
        for(int i=1;i<=mul[9]*10;i++)
        {
            if(cmp(i))
                printf("%d
    ",i);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    7牛管理凭证生成错误
    安卓截屏如何实现将摄像头显示画面截下来
    realm怎样支持hashmap
    Cordova Android项目如何做代码混淆
    cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,
    iOS中关于字符 “&”的作用?
    float 保留两位小数
    关于iOS声音识别的框架
    iOS崩溃日志
    QT分析之WebKit
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5508491.html
Copyright © 2011-2022 走看看