一、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.



二、题解

        注意精度的控制,结果控制在9位小数,String .format("%.9f",sum)。

三、java代码

public class Main {

    public static void main(String[] args) {
int i,j,fac;
double sum=2.5d;
System.out.println("n "+"e");
System.out.println("- "+"-----------");
System.out.println("0 "+"1");
System.out.println("1 "+"2");
System.out.println("2 "+"2.5");
for(i=3;i<10;i++){
fac=1;
for(j=1;j<=i;j++){
fac*=j;
}
sum+=1.0 /(fac);
System.out.print(i+" ");
System.out.println(String .format("%.9f",sum));
}
}
}

poj 1517 u Calculate e(精度控制+水题)的更多相关文章

  1. Poj 2350 Above Average(精度控制)

    一.Description It is said that 90% of frosh expect to be above average in their class. You are to pro ...

  2. OpenJudge/Poj 1517 u Calculate e

    1.链接地址: http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517 2.题目: 总时间限制: 1000ms ...

  3. poj 1517 u Calculate e

    u Calculate e Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19465   Accepted: 11362   ...

  4. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  5. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

  6. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  7. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  8. [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告

        A+B Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 311263   Accepted: 1713 ...

  9. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

随机推荐

  1. Bootstrap 第一天

    Bootstrap第一天 1.什么是Bootstrap?     Bootstrap是由两位设计开发的.     Bootstrap主要是前端的框架(HTML.CSS.JS). 2.为什么使用Boot ...

  2. 有关numpy.random下的API具体含义

    1.numpy.random.random(size=None) Return random floats in the half-open interval [0.0, 1.0). 返回size大小 ...

  3. Navicat试用期破解方法(转)

    转载网址https://blog.csdn.net/Jason_Julie/article/details/82864187 1.按步骤安装Navicat Premium,如果没有可以去官网下载:ht ...

  4. Kattis - horrorfilmnight 【贪心】

    题意 有两个人想去一起看电影,然后分别给出两个人 分别喜欢看的电影都在哪些天 然后 同一个人 不能连续看两天他不喜欢的电影 求他们最多可以看多少次电影 思路 先将两人喜欢看的电影进行排序, ① 选择两 ...

  5. nodejs模块之event

    event模块是nodejs系统中十分重要的一个模块,使用该模块我们可以实现事件的绑定的触发,为什么我们需要这个模块呢,因为nodejs是单线程异步的. 一.什么是单线程异步: 我们可以从JavaSc ...

  6. Spark Structured Streaming框架(3)之数据输出源详解

    Spark Structured streaming API支持的输出源有:Console.Memory.File和Foreach.其中Console在前两篇博文中已有详述,而Memory使用非常简单 ...

  7. 如何在 Eclipse 中使用命令行

    虽然我们已经有了像 Eclipse 这样高级的 IDE,但是我们有时候也是需要在开发的时候使用 Windows 的命令行,来运行一些独立的程序.在两个程序中切换来切换去是很麻烦的.所以 Eclipse ...

  8. hiho一下 第四十九周 题目1 : 欧拉路·一【无向图 欧拉路问题】

    题目1 : 欧拉路·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho最近在玩一个解密类的游戏,他们需要控制角色在一片原始丛林里面探险,收集道具,并找到最 ...

  9. linux基本使用

    (待完善,想到哪就写到哪,目前内容大幅度参考中文man手册) 最重要的命令(man) 在 Linux 下遇到问题,最重要的是要自己寻求帮助, google是个好东西 man 是 Linux 的帮助手册 ...

  10. Java 动态代理机制分析及扩展,第 1 部分

    Java 动态代理机制分析及扩展,第 1 部分 http://www.ibm.com/developerworks/cn/java/j-lo-proxy1/ 本文通过分析 Java 动态代理的机制和特 ...