hdoj 2212 DFS 【水】

DFS

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

Total Submission(s): 5298    Accepted Submission(s): 3252

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

这道题就是逗你玩呢。。。

分析:9的阶乘为362880, 而且由0~9的阶乘组成的最大数就是3628800,所以搜索一下就好了,结果你会很惊讶。。。

只有1, 2, 145, 40585符合。。。

代码:

#include <stdio.h>
int f[10] = {1, 1};
int a[10];

void ff(){
    int i;
    for(i = 2; i < 10; i ++) f[i] = f[i-1]*i;
    //printf("%d", f[9]);
}

int judge(int n){
    int sum1 = n, sum2;
    sum2 = 0;
    while(n){
        int temp = n%10;
        sum2 += f[temp];
        n/= 10;
    }
    if(sum1 == sum2) return 1;
    return 0;
}

int main(){
    ff();
    for(int i = 1; i <= 3628800; i ++)
        if(judge(i)) printf("%d\n", i);
    return 0;
}

也可以直接输出。。。。

时间: 2024-12-23 05:52:17

hdoj 2212 DFS 【水】的相关文章

hdu 2212 DFS(水题)

DFS Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4923    Accepted Submission(s): 3029 Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every digit

HDOJ(HDU) 2212 DFS(阶乘相关、)

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 numbe

POJ 2248 Addition Chains dfs(水)

题意:给出n 构成出满足下列条件 长度最小的数列a[0]=1,a[m]=n, a[0]<a[1]<..<a[m]每个下标k都存在(i,j<k) 满足:a[k]=a[i]+a[j] n<=100 枚举长度 dfs爆搜+剪枝 水过, #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N=2e5+20; int n,a[N

POJ 题目2245 Lotto(DFS水)

Lotto Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6549   Accepted: 4153 Description In the German Lotto you have to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't increase your chan

poj 1979 dfs水题

// 练练水题,夯实基础吧 #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib

HDOJ 4582 - DFS spanning tree - DFS树,贪心

题目大意: 给定一个N个点.M条边的无向图Graph,以及从点1开始进行DFS形成的树Tree,定义"T-Simple Circle"为Graph中的环,要求其中只含一条不属于Tree的边. 将Graph中的一些边进行染色,使得其中每个T-simple Circle都至少包含一条被染色的边,求最少需要染色的边数. N≤2e3,M≤2e4 本题关键的一点在于Tree是一棵DFS生成树,这样Tree以外的边只可能将某个点与它在Tree中的祖先相连(用反证法可以证明,只有这样才能维持DFS树

HDU 2212 DFS

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 numbe

HDOJ 1427(dfs) 速算24点

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1427 思路分析: 题目要求判断是否存在一种运算组合使得4个数的计算结果为24,因为搜索的层次为3层,不需要选择出最短的路径,采用dfs更有效: 拓展状态时,从当前状态拥有的数中选取两个进行某种运算(因为两个数之间存在大小关系,所以对于除法与减法来说,运算顺序一定, 大的数为被减数或被除数:加法与乘法具有交换律,相对顺序没有影响),如果可以进行运算且运算结果满足题目要求,则该状态可以 拓展,如此拓展状

codeforces B. Strongly Connected City(dfs水过)

题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向, 问是否每一个节点都可以由其他的节点到达.... 思路:规律没有想到,直接爆搜!每一个节点dfs一次,记录每个节节点被访问的次数!如果每个节点最终的访问次数 和所有节点的数目相同,则输出“YES", 否则输出”NO“ 1 #include <queue> 2 #include <string> 3 #include <cstdio> 4 #include &