Fork me on GitHub

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了。

posted @   Gifur  阅读(834)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
TOP
点击右上角即可分享
微信分享提示