您的位置:首页 > 其它

hdu 2212 DFS

2009-05-13 21:06 323 查看

DFS

Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 622 Accepted Submission(s): 380



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
no input

[align=left]Output[/align]
Output all the DFS number in increasing order.

[align=left]Sample Output[/align]

1
2
......


[align=left]Author[/align]
zjt

[align=left]Recommend[/align]
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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: