/*
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. extjs的formpanel横向滚动条的解决办法

    关于formpanel设置autoscroll:true同时出现横向和纵向滚动条的解决办法: 不要设置autoscroll属性,或者autoscroll:false,然后设置bodyStyle : ' ...

  2. HDU - 3622 Bomb Game(二分+2-SAT)

    题目大意:玩一个放炸弹游戏,有N次放炸弹的机会,每次放炸弹时,你都有两个位置能够选择.问怎样放炸弹,能使爆炸的炸弹的半径的最小值最大(炸弹爆炸半径能够控制,可是爆炸形成的圈不能有重叠部分) 解题思路: ...

  3. poi读取word2003(.doc文档)中的表格

    poi读取word2003(.doc文档)中的表格 Jakarta POI 是apache的子项目,目标是处理ole2对象.它提供了一组操纵Windows文档的Java API.在网上见到好多通过po ...

  4. Socket之shutdown()用法

    通常来说,socket是双向的,即数据是双向通信的.但有些时候,你会想在socket上实现单向的socket,即数据往一个方向传输. 单向的socket便称为半开放Socket.要实现半开放式,需要用 ...

  5. [Apple开发者帐户帮助]二、管理你的团队(3)删除团队成员

    如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到App Store Connect帮助中的添加和编辑用户. 如果您已加入Apple Dev ...

  6. LeetCode.3-最长无重复字符子串(Longest Substring Without Repeating Characters)

    这是悦乐书的第341次更新,第365篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第2题Longest Substring Without Repeating Cha ...

  7. C99C新增内容

    继上一篇复合文字之后,今天我们继续谈一谈C99C的新特性. C99标准是继C89标准之后的第二个C语言官方标准,于1999年12月1日正式发布,其中对数据类型(增加了对_Bool),关键字(增加了in ...

  8. 在PL/SQL中使用游标、动态sql和绑定变量的小例子

    需求:查询并输出30号部门的雇员信息 方式一:使用 loop...fetch SET serveroutput ON; DECLARE CURSOR c_emp IS ; v_emp emp%rowt ...

  9. Android 4.0 Launcher2源码分析——主布局文件(转)

    本文来自http://blog.csdn.net/chenshaoyang0011 Android系统的一大特色是它拥有的桌面通知系统,不同于IOS的桌面管理,Android有一个桌面系统用于管理和展 ...

  10. SQL优化--使用 EXISTS 代替 IN 和 inner join来选择正确的执行计划

    在使用Exists时,如果能正确使用,有时会提高查询速度: 1,使用Exists代替inner join 2,使用Exists代替 in 1,使用Exists代替inner join例子: 在一般写s ...