码迷,mamicode.com
首页 > 其他好文 > 详细

HDU_2212_水

时间:2016-05-19 15:07:20      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

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\n",i);
    }
    return 0;
}
View Code

 

HDU_2212_水

标签:

原文地址:http://www.cnblogs.com/jasonlixuetao/p/5508491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!