poj 1517 & 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 of e using relatively small values of n.

Input

No input

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 Input

no input

Sample Output

n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
...

Source

Greater New York 2000

注意:poj上用G++交WA了,用C++AC,HDU上则不存在此问题。

代码如下:

#include <cstdio>
int Fac(int n)
{
    int s=1;
    for(int i=1; i<=n; i++)
        s*=i;
    return s;
}
int main()
{
    double sum;
    printf("n e\n- -----------\n");
    for(int i = 0; i <= 9; i++)
    {
        sum = 1;
        for(int j = 1; j <= i; j++)
        {
            sum+=1.0/Fac(j);
        }
        if(i <= 1)
            printf("%d %.0lf\n",i,sum);
        else if(i == 2)
            printf("2 2.5\n");
        else if(i > 2)
            printf("%d %.9lf\n",i,sum);
    }
    return 0;
}

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

时间: 2024-08-08 03:59:52

poj 1517 & hdu 1012 u Calculate e(简单阶乘)的相关文章

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(简单阶乘计算)

传送门: 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

水题/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

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

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

POJ 1018 &amp; HDU 1432 Lining Up 【简单几何】

Lining Up Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24786   Accepted: 7767 Description "How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at spe

POJ 2411 &amp;&amp; HDU 1400 Mondriaan&#39;s Dream (状压dp 经典题)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12341   Accepted: 7204 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

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