Harmonic Number 求Hn; Hn = 1 + 1/2 + 1/3 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8; 打表或者调和级数
/**
题目:Harmonic Number
链接:https://vjudge.net/contest/154246#problem/I
题意:求Hn; Hn = 1 + 1/2 + 1/3 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8;
思路:由于1e8,所以直接存表不行。
通过每100个存入数组一个变量值。然后每次查询最多100次就可以了。 其他解法转自http://www.cnblogs.com/shentr/p/5296462.html:
知识点: 调和级数(即f(n))至今没有一个完全正确的公式,但欧拉给出过一个近似公式:(n很大时)
f(n)≈ln(n)+C+1.0/(2*n)
欧拉常数值:C≈0.57721566490153286060651209
c++ math库中,log即为ln。 公式:f(n)=ln(n)+C+1.0/(2*n);
n很小时直接求,此时公式不是很准。 */ #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e4+;
const int N = 1e8;
double a[]; void init()
{
double p = ;
for(int i = ; i <= N; i++){
p += 1.0/i;
if(i%==)
a[i/] = p;
}
}
int main()
{
int T, n, cas=;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
init(); cin>>T;
while(T--)
{
scanf("%d",&n);
double p = ;
for(int i = n/*+; i <= n; i++){
p += 1.0/i;
}
printf("Case %d: %.10lf\n",cas++,p+a[n/]);
} return ;
}
/**
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double C=0.57721566490153286060651209;
double a[10004];
void init()
{
for(int i = 1; i <= 10000; i++){
a[i] = a[i-1]+1.0/i;
}
}
int main()
{
int T, n, cas=1;
init();
cin>>T;
while(T--)
{
scanf("%d",&n);
printf("Case %d: ",cas++);
if(n<=10000){
printf("%.10lf\n",a[n]);
}else
printf("%.10lf\n",log(n)+C+1.0/(2*n));
}
return 0;
}
*/
Harmonic Number 求Hn; Hn = 1 + 1/2 + 1/3 + ... + 1/n; (n<=1e8) T<=1e4; 精确到1e-8; 打表或者调和级数的更多相关文章
- G - Harmonic Number (II) 找规律--> 给定一个数n,求n除以1~n这n个数的和。n达到2^31 - 1;
/** 题目:G - Harmonic Number (II) 链接:https://vjudge.net/contest/154246#problem/G 题意:给定一个数n,求n除以1~n这n个数 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- LightOJ 1234 Harmonic Number
D - Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu S ...
- Harmonic Number(调和级数+欧拉常数)
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers ...
- LightOJ 1234 Harmonic Number(打表 + 技巧)
http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS Memory ...
- LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- LightOJ 1234 Harmonic Number (打表)
Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- Harmonic Number (调和级数+欧拉常数)题解
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- LightOJ1234 Harmonic Number —— 分区打表
题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number PDF (English) Statistics Foru ...
随机推荐
- iOS数据库操作(使用FMDB)
iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...
- 百度地图API的事件处理:覆盖物的如何阻止冒泡
百度地图,为了让事件使用的更方便,进行一层封装 详情可以看官方的文档 http://developer.baidu.com/map/jsdevelop-5.htm 主要的修改点: 1. 使用事件代理. ...
- 上手 Webpack ? 这篇就够了!
JavaSript 模块化打包已混迹江湖许久.2009年,RequireJS 就提交了它的第一个版本,Browserify 接踵而至,随后其他打包工具也开始大行其道.最终,Webpack 从其中脱颖而 ...
- ueditor-angular(百度编辑器angular版)中,关于插入图片后不操作,图片无法正常提交的问题;
由于项目后台管理页面中需要使用编辑器,所以选择了百度编辑器这个常用的东西: 本人是小白,第一次使用百度编辑器,具体的配置是由后台的兄弟完成的,还给了demo,所以在项目开发中也一直都没发现什么问题: ...
- TSynDBSQLDataSet
TSynDBSQLDataSet 非内存表 TSynDBSQLDataSet = class(TSynBinaryDataSet) TSynBinaryDataSet = class(TSynVirt ...
- css活用,半星星的效果
1.首先下载要用到星星字体 http://www.w3cplus.com/w3cplusDemo/demos/webFontIcon.html 2.css .cleanfloat::after{dis ...
- java面试题目
1.Java中的异常处理机制的简单原理和应用.当JAVA程序违反了JAVA的语义规则时,JAVA虚拟机就会将发生的错误表示为一个异常.违反语义规则包括2种情况.一种是JAVA类库内置的语义检查.例如数 ...
- Linq-语句之Select/Distinct和Count/Sum/Min/Max/Avg
上一篇讲述了LINQ,顺便说了一下Where操作,这篇开始我们继续说LINQ to SQL语句,目的让大家从语句的角度了解LINQ,LINQ包括LINQ to Objects.LINQ to Data ...
- 表单提交时上传图片 表单ajax提交
页面 <script type="text/javascript" src="js/jquery.form.js"></script>& ...
- rails generate model/resource/scaffold的区别
If you’re just learning Ruby on Rails, you may be confused as to when to generate individual models, ...