/*
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的更多相关文章

  1. LightOJ1234 Harmonic Number —— 分区打表

    题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number    PDF (English) Statistics Foru ...

  2. LightOJ1234 Harmonic Number 调和级数求和

    [题目] [预备知识] ,其中r是欧拉常数,const double r= 0.57721566490153286060651209; 这个等式在n很大 的时候 比较精确. [解法]可以在 n较小的时 ...

  3. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  4. LightOJ 1234 Harmonic Number

    D - Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu S ...

  5. LightOJ 1234 Harmonic Number (打表)

    Harmonic Number Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submi ...

  6. LightOJ 1245 Harmonic Number (II)(找规律)

    http://lightoj.com/volume_showproblem.php?problem=1245 G - Harmonic Number (II) Time Limit:3000MS    ...

  7. 1245 - Harmonic Number (II)(规律题)

    1245 - Harmonic Number (II)   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 3 ...

  8. Harmonic Number(调和级数+欧拉常数)

    In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers ...

  9. Harmonic Number (调和级数+欧拉常数)题解

    Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...

随机推荐

  1. MySQL 相邻两条数据相减

    <!-- 计算每两次消费的间隔天数 --> SELECT B.MEN_ID,TIMESTAMPDIFF(DAY,B.PRE_DATE,B.CURR_DATE) AS DAYS FROM ( ...

  2. 微信小程序初探(二、分页数据请求)

    大家好 波哥小猿又来啦[斜眼笑],昨天咱们讲了微信小程序简单数据请求,有没有照着教程实现请求的同学们啦 实现的同学举个爪[笑脸].哈哈,好了不扯犊子啦,我相信有的同学已经实现了简单的数据请求,没有实现 ...

  3. bzoj4950: [Wf2017]Mission Improbable

    跟着靖靖做题%%%%% 这题一看就觉得和之前的某场模拟赛的一道题很像,找假如某行某列的最大值一样的就可以只堆一个,跑匈牙利就行 一开始以为箱子不能移动-_-! 然后有个坑,大家都知道当这个位置有箱子就 ...

  4. hdu1704——floyd

    Problem Description there are N ACMers in HDU team.ZJPCPC Sunny Cup 2007 is coming, and lcy want to ...

  5. Reactive Native开发环境搭建

    root@zhongzhenhua-virtual-machine:~/AndroidCode# repo init -u https://android.googlesource.com/platf ...

  6. codevs1688 求逆序对(权值线段树)

    1688 求逆序对  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 给定一个序列a1,a2,…, ...

  7. 洛谷P3047 [USACO12FEB]Nearby Cows(树形dp)

    P3047 [USACO12FEB]附近的牛Nearby Cows 题目描述 Farmer John has noticed that his cows often move between near ...

  8. Gym - 101981A The 2018 ICPC Asia Nanjing Regional Contest A.Adrien and Austin 简单博弈

    题面 题意:一堆有n个石子,编号从1⋯N排成一列,两个人Adrien 和Austin玩游戏,每次可以取1⋯K个连续编号的石子,Adrien先手,谁不能取了则输 题解:k==1时,显然和n奇偶相关,当k ...

  9. centos7安装python3.7和ipython

    一.centos7为刚安装的 1)配置yum源和epel源 采用国内源 查看yum的配置文件 (里面的镜像网址)是否ping的通 全部更改成 国内的 yum .epel源 在图中位置 下载相应的 re ...

  10. Android插件化原理解析——Hook机制之动态代理

    转自 http://weishu.me/2016/01/28/understand-plugin-framework-proxy-hook/ 使用代理机制进行API Hook进而达到方法增强是框架的常 ...