• hdu 2212 DFS


    DFS

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


    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
    ......
     

    Author
    zjt
     

    Recommend
    lcy
     

    Statistic | Submit | Back
    //1364495 2009-05-13 20:42:44 Time Limit Exceeded 2212 2000MS 232K 426 B C++ Wpl
    //1364655 2009-05-13 21:03:44 Accepted 2212 0MS 204K 299 B C++ Wpl  
    /*
    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] ).
    */
    #include 
    <iostream>
    #define MAX 5
    using namespace std;
    int data[MAX];
    int main()
    {
        data[
    0]=1;
        data[
    1]=2;
        data[
    2]=145;
        data[
    3]=40585;
        
    int i;
        
    for(i=0;i<=3;i++)
            printf(
    "%d\n",data[i]);
        
    return 0;
    }


    附上打表的程序

    //1364495 2009-05-13 20:42:44 Time Limit Exceeded 2212 2000MS 232K 426 B C++ Wpl 
    #include <iostream>
    #include 
    <fstream>
    #define MAX 10000
    using namespace std;
    int f[11],data[MAX];
    bool DFS(int n)
    {
        
    int sum=0,x=n;
        
    while(x!=0)
        {
            sum
    +=f[x%10];
            x
    =x/10;
            
    if(sum>n)
                
    return false;
        }
        
    if(sum==n)
            
    return true;
        
    else
            
    return false;
    }
    int main()
    {
        
    int i,j;
        f[
    0]=1;
        
    for(i=1;i<=10;i++)
            f[i]
    =i*f[i-1];
        ofstream outfile(
    "ans.txt");
        j
    =0;
        
    for(i=1;i<2147483647;i++)
        {
            
    if(DFS(i))
            {
                outfile
    <<"data["<<j++<<"]="<<i<<endl;
            }
        }
        
    return 0;
    }
  • 相关阅读:
    已整理Linux进程概念与常用操作
    Linux vsftpd服务配置
    已整理制作ceph离线安装包
    时间同步服务与客户端配置
    已整理rpm 包管理与yum服务器配置操作
    通用池化框架GenericObjectPool性能测试
    红利、辛苦钱、利润和工资【读书笔记】
    通用池化框架GenericKeyedObjectPool性能测试
    国际化和本地化测试
    Redis stream Java API实践
  • 原文地址:https://www.cnblogs.com/forever4444/p/1456263.html
Copyright © 2020-2023  润新知