题目1038:Sum of Factorials

千呼万唤死出来!!!!

此题的思路,多少有点接受不了,竟然让所给值逐一减去大值,再看所剩值是否为零来判断,

所以就需要一个值或数组来记录所有的阶乘和,那么问题来了,如何记录,如何求取。

我用的是num数组一边求取一边记录

还有一种利用外部函数int fact(int n)来调用的;

还有这种:需要眼力和经验

for(i = 1;i < 11;i ++){
                number[i] = i * number[i -1]; }

还有一种更绝的:简直无语!!!!!!!

int f[10]={1,1,2,6,24,120,720,5040,40320,362880};

再来AC 的代码:

#include <iostream>
using namespace std;

int main()
{
	int num[11];
	int i,j,n;
	 num[0] = 1;
        for(i = 1;i < 11;i ++){
                num[i] = i * num[i -1];
        }
	while(cin>>n)
	{
		if (n==0) {
	cout<<"NO"<<endl;continue;	}
		for (i=10;i>=0;i--)
		{
			if (n>=num[i])
			   n-=num[i];
		}
		if (n==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;

	}
	return 0;
}

 

时间: 2024-08-24 23:54:41

题目1038:Sum of Factorials的相关文章

九度OJ 1038 Sum of factorials (模拟)

题目1038:Sum of Factorials 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1491 解决:635 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum phy

1038.sum of factorials

题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics, meteorology, science, computers, and game theory. He was not

每日一九度之 题目1038:Sum of Factorials

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics, meteorology, scienc

zoj 2358,poj 1775 Sum of Factorials(数学题)

题目poj 题目zoj //我感觉是题目表述不确切,比如他没规定xi能不能重复,比如都用1,那么除了0,都是YES了 //算了,这种题目,百度来的过程,多看看记住就好 //题目意思:判断一个非负整数n能否表示成几个数的阶乘之和 //这里有一个重要结论:n!>(0!+1!+……+(n-1)!), //证明很容易,当i<=n-1时,i!<=(n-1)!,故(0!+1!+……+(n-1)!)<=n*(n-1)!=n!. // 由于题目规定n<=1000000,而10!=362880

POJ 1775 Sum of Factorials

题目: Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics,meteorology, science, computers, and game theory. H

poj 1775 &amp;&amp; zoj 2358 Sum of Factorials

Sum of Factorials Time Limit: 1000MS Memory Limit: 30000K Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physi

leetcode题目:Sum Root to Leaf Numbers和Longest Consecutive Sequence

题目一: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. For example, 1 /

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

[POJ]_1775_Sum of Factorials

题目: Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics,meteorology, science, computers, and game theory. H