poj 1517 u Calculate e(精度控制+水题)
一、Description
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
Output
二、题解
注意精度的控制,结果控制在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(精度控制+水题)的更多相关文章
- Poj 2350 Above Average(精度控制)
一.Description It is said that 90% of frosh expect to be above average in their class. You are to pro ...
- OpenJudge/Poj 1517 u Calculate e
1.链接地址: http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517 2.题目: 总时间限制: 1000ms ...
- poj 1517 u Calculate e
u Calculate e Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19465 Accepted: 11362 ...
- POJ 3254 - Corn Fields - [状压DP水题]
题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...
- POJ 3369 Meteor Shower (BFS,水题)
题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告
A+B Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 311263 Accepted: 1713 ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
随机推荐
- oschina git服务, 如何生成并部署ssh key
1.如何生成ssh公钥 你可以按如下命令来生成 sshkey: ssh-keygen -t rsa -C "xxxxx@xxxxx.com" # Generating public ...
- PHP自定义函数: 下载远程文件
function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo($url,PATH ...
- WndProc漏写override会发生什么情况?
试图改写TForm1(注意,不是TForm类)的WndProc函数,从而达到某些目的.程序如下: unit Unit1; interface uses Windows, Messages, SysUt ...
- hibernate 多对多操作(级联操作)
一.级联保存 分别在用户和角色配置文件中在set标签中加入cascade="save-update": 示例:添加同时添加用户对象和角色对象并关联两个对象: 只需将角色放入用户对象 ...
- linux c编程:标准IO库
前面介绍对文件进行操作的时候,使用的是open,read,write函数.这一章将要介绍基于流的文件操作方法:fopen,fread,fwrite.这两种方式的区别是什么呢.1种是缓冲文件系统,一种是 ...
- 11.23 Eclipse
一.Eclipse Workspace File-->Switch Workspace 编译环境:Window -- Preferences – Java - Compiler 运行环境:Win ...
- Yii2 如何更好的在页面注入CSS
首先 先添加一个widgets,代码如下(提示:使用时注意修改命名空间) <?php /** * User: yiqing * Date: 2014/12/15 * Time: 0:21 */ ...
- 3.16课·········C#小结
//附加//C#源码,被C#编译器,编译成执念代码(IL)//int16=short.....±32000//int32=int.......±21亿//int64=long......±922亿亿3 ...
- 如何在unigui中用代码展开一棵树?
procedure expandtree(tree:tunitreeview);begin UniSession.AddJS('setTimeout("' + Tree1.JSName ...
- 算法(Algorithms)第4版 练习 1.4.6
(1)sum = N + N/2 + N/4 + …… + 1 假设N是2的倍数(N = 2q),则sum = N -1 ~ N (2)sum = 1+2+……N/2 同(1)分析,sum = N/ ...