HDU_2212_水
Posted Jason333
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU_2212_水相关的知识,希望对你有一定的参考价值。
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.
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; }
以上是关于HDU_2212_水的主要内容,如果未能解决你的问题,请参考以下文章
hdu_2124 Flying to the Mars & hdu_1800 Repair the Wall 贪心水题
HDU1009_FatMouse' Trade贪心水题