/*
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. pass an instance of class to TestCase as parameter

    use testcasesource instead https://stackoverflow.com/questions/4220943/how-to-pass-dynamic-objects-i ...

  2. 洛谷P3809 后缀数组模板

    题目:https://www.luogu.org/problemnew/show/P3809 刚学了后缀数组,看人家手写演示了半天,大概明白了过程,但完全写不出来代码: 于是借鉴了许多,不过都差不多, ...

  3. 纯CSS 实现关闭图标 icon

    本文介绍关闭 icon 的实现.具体如下 1.html部分 <span id="close"></span> 2.css部分 #close { displa ...

  4. clone的rails目录下命令无效问题

    异常坑爹,在公司克隆自己的项目.然后在项目目录下rails s还有一大堆命令无效,提示 Usage: rails new APP_PATH [options]   找了半天总算找到解决办法了,在项目目 ...

  5. python重定向原理及实例

    1. 前言 为了在Python编程中, 利用控制台信息, 我们需要对控制台输出进行接管(重定向).在Python中,控制台输出的接口是sys.stdout,通过分析print与sys.stdout之间 ...

  6. Unity中内嵌网页插件UniWebView

    一.常见Unity中内嵌网页实现方式: 1.UnityWebCore只支持windows 2.Unity-Webview支持Android,IOS 3.UniWebView支持mac os,Andro ...

  7. Java创建Excel-DEMO

    import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Out ...

  8. js视频学习笔记1

    1:数组赋值的个数长度定义无效,第4个存储的数还是能原封不动打印出来. js的数组是内部有一个变量名叫0,它的值是1,有一变量名叫1,它的值是2.是这样表示的 2:js是弱类型语言,没有var标识符, ...

  9. 【Linux】ubuntu中怪异的vi编辑器

    由于前几天一场windows系统的比特币勒索病毒,我下狠心装了Linux的ubuntu版本.可是今天在使用命令行中的vi编辑器时出现了怪异的现象:backspace不能删除,编辑模式回车随机出现字母. ...

  10. Interrupt中断线程

    package com.wistron.swpc.ecs.util; public class WrongWayStopThread extends Thread{ public static voi ...