LightOJ1234 Harmonic Number
/*
LightOJ1234 Harmonic Number
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1234
打表 分块
由于只有加法运算,1e8时间是可以承受的。
然而空间无法承受,于是以50个单位为一块进行分块。
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <set>
//#define test
using namespace std;
#ifdef old
const int Nmax=1e6+;
double f[Nmax];
#endif
const int Nmax=1e8+;
const double eps=1e-;
double f[Nmax/+];
//double get_f(int n)
//{
//if(n<Nmax)
//return f[n];
//return 1.0/n+get_f(n-1);
//}
#ifdef old
map<int ,double> mp;
map<int ,double>::iterator it;
double get_f(int n)
{
if(n<Nmax)
return f[n];
it=mp.find(n);
if(it!=mp.end())
return mp[n];
it=mp.upper_bound(n);
if(it!=mp.begin())
it--;
//printf("it->n:%d\n,it->first);
double ans=it->second;
for(int i=it->first+;i<=n;i++)
{
ans+=1.0/i;
}
mp[n]=ans;
return ans;
}
#endif
int main()
{
#ifdef test
#endif
//freopen("loj1234.in","r",stdin);
//freopen("tras.out","w",stdout);
#ifdef old
f[]=1.0;
for(int i=;i<Nmax;i++)
f[i]=f[i-]+1.0/i;
#endif
//for(int i=1;i<=15;i++)
//printf("%lf\n",f[i]);
#ifdef old
mp[Nmax-]=f[Nmax-];
#endif
double tmp=0.0;
for(int i=;i<=1e8;i++)
{
tmp+=1.0/i;
if(i%==)
f[i/]=tmp;
}
int n;
int t;
scanf("%d",&t);
t=;
while(scanf("%d",&n)==)
{
t++;
printf("Case %d: ",t);
double ans=0.0;
ans=f[n/];
for(int i=n/*+;i<=n;i++)
ans+=1.0/i;
printf("%.8lf\n",ans+eps);
#ifdef old
printf("%.8lf\n",get_f(n)+eps);
#endif }
return ;
}
LightOJ1234 Harmonic Number的更多相关文章
- LightOJ1234 Harmonic Number —— 分区打表
题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number PDF (English) Statistics Foru ...
- LightOJ1234 Harmonic Number 调和级数求和
[题目] [预备知识] ,其中r是欧拉常数,const double r= 0.57721566490153286060651209; 这个等式在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 ...
- LightOJ 1234 Harmonic Number (打表)
Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...
- LightOJ 1245 Harmonic Number (II)(找规律)
http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS ...
- 1245 - Harmonic Number (II)(规律题)
1245 - Harmonic Number (II) PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...
- Harmonic Number(调和级数+欧拉常数)
In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers ...
- Harmonic Number (调和级数+欧拉常数)题解
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
随机推荐
- Extjs TabPanel页签转换事件
listeners : { tabchange : function(tp, p) { var allmapDIV = document.getElementById("allmap&quo ...
- Struts 配置文件
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...
- poj 3662 Telephone Lines(最短路+二分)
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6973 Accepted: 2554 D ...
- hdoj--5100--Chessboard(数学推理)
Chessboard Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- RPC通信框架——RCF介绍
现有的软件中用了大量的COM接口,导致无法跨平台,当然由于与Windows结合的太紧密,还有很多无法跨平台的地方.那么为了实现跨平台,支持Linux系统,以及后续的分布式,首要任务是去除COM接口. ...
- bzoj2763: [JLOI2011]飞行路线(分层图spfa)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3234 Solved: 1235[Submit][Stat ...
- bzoj2287【POJ Challenge】消失之物(退背包)
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 657 Solved: 382[Submit][S ...
- centos7用rpm安装mysql5.7【初始用yum安装发现下载非常慢,就考虑本地用迅雷下载rpm方式安装】
1.下载 4个rpm包 mysql-community-client-5.7.26-1.el7.x86_64.rpmmysql-community-common-5.7.26-1.el7.x86_64 ...
- 2015 多校赛 第二场 1006 (hdu 5305)
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
- bug,实现类未找到service