hdu 2212 DFS

本文介绍了一种特殊类型的整数——数字因子和数(DFS数),并提供了使用C++编程语言实现的两种方法来找出指定范围内的所有DFS数。一种是直接输出已知的DFS数,另一种是通过编写打表程序来找出这些数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

转载于:https://www.cnblogs.com/forever4444/archive/2009/05/13/1456263.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值