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 ...
随机推荐
- JavaSE目录
常识,环境变量,注释 标示符,常量,进制转换,类型转换,位运算符,语句 数组,函数 面向对象 多线程 String 包装类 集合 其他对象 IO流,IO流--FileReader&&F ...
- python 使用mysql示例
安装MySQL驱动 由于MySQL服务器以独立的进程运行,并通过网络对外服务,所以,需要支持Python的MySQL驱动来连接到MySQL服务器.MySQL官方提供了mysql-connector-p ...
- C语言实现括号配对问题
代码如下: #include<stdio.h> #include<string.h> #include<stdlib.h> // 写一个判断的括号是否匹配的函数 i ...
- 导出pem证书给服务端Push Notification使用
1. 钥匙串创建Push证书的证书签名请求文件(CSR文件). 如下图所示: 2.创建App ID,创建Provisioning Profile,下载安装到XCode. 苹果开发者后台页面,创建Pus ...
- 手把手教你使用FineUI开发一个b/s结构的取送货管理信息系统系列博文索引
近阶段接到一些b/s类型的软件项目,但是团队成员之前大部分没有这方面的开发经验,于是自己选择了一套目前网上比较容易上手的开发框架(FineUI),计划录制一套视频讲座,来讲解如何利用FineUI快速开 ...
- WebServic dynamic url
How to make your Web Reference proxy URL dynamic 开发环境和部署环境,Webservice 的URL不同 需将url 配置到 web.config文件中 ...
- html里嵌入CSS的三种方式
在HTML中定义CSS的方式有:Embedding(嵌入式).Linking(引用式).Inline(内联式),下面通过实例为大家详细介绍下它们的特点 在HTML中常用以下3种方式定义CSS:Em ...
- wireshark----教你怎样抓包
wireshark----教你怎样抓包 wireshark是一款强大的抓包工具,走过路过一定不要错过就是了,当你学习TCP/IP协议的时候,学习使用wireshark抓包正是理论联系实际最好的方法,先 ...
- grpc(3):使用 golang 开发 grpc 服务端和client
1,关于grpc-go golang 能够能够做grpc的服务端和client. 官网的文档: http://www.grpc.io/docs/quickstart/go.html https://g ...
- require.js - 详解
测试结构如下 index.html <!DOCTYPE html> <html lang="en"> <head> <meta chars ...