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 ...
随机推荐
- nullptr 与 constexpr
nullptr nullptr出现的目的自然是替换NULL的低位.C++可能会将NULL.0视为同一种东西.这取决于编译器是如何定义的,有的编译器定义NULL为 ( (void * )0) ,有的 ...
- CentOS7 rc.local开机开法启动
CentOS 7添加开机启动服务/脚本 一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例):systemctl enable jenkins.s ...
- java源码阅读StringBuilder
1类签名与注释 public final class StringBuilder extends AbstractStringBuilder implements java.io.Serializab ...
- Python 自用代码(递归清洗采标情况)
将‘ISO 3408-1-2006,MOD ISO 3408-2-1991,MOD ISO 3408-3-2006,MOD’类似格式字符串存为: [{'code': 'ISO 3408-1-200 ...
- js获取url參数值的两种方式具体解释
有个url例如以下: http://passport.csdn.net/account/login? from=http%3a%2f%2fwrite.blog.csdn.net%2fpostedit ...
- 微信小程序 - 更改button状态
wxml <button class='yes-orders' style='{{status_css}}' bindtap='clickExpress'> {{statusOrders} ...
- js 自定义事件 包含 添加、激活、销毁
1.思路 (1)构思 var eventTarget = { addEvent: function(){ //添加事件 }, fireEvent: function(){ //触发事件 }, remo ...
- php RSA 加密 与java加密互交,java解密
<? php class encrypt{ var $pub_key; function redPukey() { $pubKey = "MIIDhzCCAm+gAwIBAgIGASY ...
- 由friend用法引出的声明与定义那些事儿
今天遇到了一个问题,大致描述一下就是有两个类A和B.我想达到如下效果:B是A的友元,同时A是B的类类型成员. 第一次尝试,在B.h中包含A.h,在A.h中包含B.h,在A类中声明friend clas ...
- Python人体肤色检测
代码地址如下:http://www.demodashi.com/demo/12967.html Python人体肤色检测 概述 本文中的人体肤色检测功能采用 OpenCV 库实现, OpenCV是一个 ...