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: ...
随机推荐
- Nginx结合GeoIP库
1. 编译nginx时带上geoip模块 # wget http://nginx.org/download/nginx-x.x.x.tar.gz # tar zxvf nginx-x.x.x.tar. ...
- (转)Spring 缓存EhCacheFactoryBean
Spring使用Cache 从3.1开始,Spring引入了对Cache的支持.其使用方法和原理都类似于Spring对事务管理的支持.Spring Cache是作用在方法上的,其核心思想是这样的:当我 ...
- mapreduce源码解析以及优化
http://blog.csdn.net/wisgood/article/details/8793483 优化 http://blog.csdn.net/wisgood/article/details ...
- 总结:iview(基于vue.js的开源ui组件)学习的一些坑
1.要改变组件的样式 找到这个组件的class名,然后覆盖样式. 举例:修改select框,显示圆角.只需给找到类名并写样 .ivu-select-selection{ border-radius:1 ...
- Docker Copy On Write
Container分成结构 Container最上面是一个可写的容器层,以及若干只读的镜像层组成,Container的数据就存放在这些层中,这样的分层结构最大的特性是Copy-On-Write: 1. ...
- LINQ 学习路程 -- 查询操作 Select, SelectMany
IList<Student> studentList = new List<Student>() { , StudentName = "John" }, , ...
- Network IP Availability Extension
可以查询网络的IP使用情况 neutron net-ip-availability-list neutron net-ip-availability-show GET /v2.0/network-ip ...
- linux 各个文件系统之间的关系
linux 系统的各个文件系统是内置于内核中的,用vfs屏蔽了各个文件系统对于文件操作的差异,用户进程是通过系统调用来操作文件系统中的文件的.
- Xcode 中代码提示不显示
解决办法: Xcode->Window->Organizer->Projects选中你的项目,点击如下图Derived Data右侧的Delete按钮 DerivedData从字面上 ...
- BZOJ 2002 [Hnoi2010]Bounce 弹飞绵羊:分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆 ...