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 ;
}

你可能感兴趣的:(HDU)