HDU 1012 u Calculate e(简单阶乘计算)

传送门:

http://acm.hdu.edu.cn/showproblem.php?pid=1012

u Calculate e

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 52607    Accepted Submission(s): 24106

Problem Description

A simple mathematical formula for e is

where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.

Output

Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.

Sample Output

n e

- -----------

0 1

1 2

2 2.5

3 2.666666667

4 2.708333333

Source

Greater New York 2000

分析:

没有什么好说的

水题

code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int f(int x)
{
    if(x==0)
        return 1;
    if(x==1)
        return 1;
    LL sum=1;
    for(int i=1;i<=x;i++)
    {
        sum*=i;
    }
    return sum;
}
int main()
{
    printf("n e\n");
    printf("- -----------\n");
    printf("0 1\n1 2\n2 2.5\n");
    for(int i=3;i<=9;i++)
    {
        double result=0;
        for(int j=0;j<=i;j++)
        {
            result+=(1.0/(f(j)*1.0));
        }
        printf("%d %0.9lf\n",i,result);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/yinbiao/p/9313265.html

时间: 2024-12-28 12:21:48

HDU 1012 u Calculate e(简单阶乘计算)的相关文章

poj 1517 &amp; hdu 1012 u Calculate e(简单阶乘)

POJ链接 :http://poj.org/problem?id=1517 HDU链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 Description A simple mathematical formula for e is e=Σ0<=i<=n1/i! where n is allowed to go to infinity. This can actually yield very accurate approximations o

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

水题/hdu 1012 u Calculate e

题意 求n=0~9时的sigma(1/n!) 分析 因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题 Accepted Code 1 /* 2 PROBLEM:hdu 1012 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 #include<iostream> 7 #include<iomanip> 8 using namespace std; 9 double a[10]; 10 int main() 11 { 12 cout<&l

HDU 1012 u Calculate e【暴力打表,水】

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s): 21489 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

HDU 1012.u Calculate e【水】【8月16】

u Calculate e Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n. Output Output the approximations of e generat

PTA之简单阶乘计算

本题要求实现一个计算非负整数阶乘的简单函数. 时间限制: 400ms 内存限制: 64MB 代码长度限制: 16KB 函数接口定义: int Factorial( const int N ); 其中N是用户传入的参数,其值不超过12.如果N是非负整数,则该函数必须返回N的阶乘,否则返回0. 裁判测试程序样例: 1 #include <stdio.h> 2 int Factorial(const int N); 3 int main() 4 { 5 int N, NF; 6 scanf_s(&q

Hdu 1012 u Calculate e

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46276    Accepted Submission(s): 21237 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

杭电 1012 u Calculate e【算阶乘】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解题思路:对阶乘递归求和 反思:前面3个的输出格式需要注意,可以自己单独打印出来,也可以在for循环里面更改输出小数的位数,另外读题还是要仔细,输出的有9位小数. #include<stdio.h> double sum(int n) { int i; double x=1,s=0; if(n==0) return 1; else { s=1; for(i=1;i<=n;i++) {

hdu 4970 Killing Monsters(简单题) 2014多校训练第9场

Killing Monsters                                                                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Kingdom Rush is a popular TD game, in which you should b