zoukankan      html  css  js  c++  java
  • ACM 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): 19296 Accepted Submission(s): 8425


    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
     
    Recommend
    JGShining
     
     
    #include<stdio.h>
    #include<string.h>
    double run(int n)
    {
        if(n == 0 || n == 1) return 1;
        else return run(n-1)*n;
    }
    
    int main()
    {
        int n, i, j;
        double sum[11];
        memset(sum, 0, sizeof(sum));
        printf("n e\n- -----------\n0 1\n1 2\n2 2.5\n");
        sum[2] = 2.5;
        for(i=3; i<=9; i++)
        {
            sum[i] = sum[i-1] + 1.0/run(i);
            printf("%d %.9lf\n", i, sum[i]);
        }
    }


    结题报告:

    WA的情况并没有那么唯一的,捉襟见肘的感觉很难见到AC的那一刻,做题需要严谨和耐心,WA多次没问题,挣扎成长只是暂时

    如果没有这个提示,我想我会再禁锢一段时间

    n e
    - -----------
    0 1
    1 2
    2 2.5
    3 2.666666667
    4 2.708333333
    5 2.716666667
    6 2.718055556
    7 2.718253968
    8 2.718278770
    9 2.718281526

    这是AC的数据,注意n=8的情况,最后面无意义的0还是要保留。所以n=0、1、2作为特殊值输出,剩下的用%.9lf即可,%.10lg就要WA了。

    物役记

    更多内容请关注个人微信公众号 物役记 (微信号:materialchains)

  • 相关阅读:
    Python中*和**的区别
    Python中str、list、numpy分片操作
    Python中bisect的使用方法
    Python中__str__和__repr__的区别
    Python中函数参数类型和参数绑定
    C++中explicit
    C++中const
    自动识别 URL
    .net中activex的替代技术:winform control(一)
    vs2005包加载有误的解决方法
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2699098.html
Copyright © 2011-2022 走看看