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 ...
随机推荐
- 组合数们&&错排&&容斥原理
最近做了不少的组合数的题这里简单总结一下下 1.n,m很大p很小 且p为素数p要1e7以下的 可以接受On的时间和空间然后预处理阶乘 Lucas定理来做以下是代码 /*Hdu3037 Saving B ...
- arm下用shell控制gpio
创建脚本gpio.sh #!/bin/sh PIN=$ VALUE=$ if test -d /sys/class/gpio/gpio$PIN/ then echo $VALUE > /sys/ ...
- 安卓Recovery模式该怎么用?【转】
本文转载自:http://android.baike.com/article-109914.html 安卓系统出了名的刷机刷机再刷机,说起刷机就不能不谈Recovery模式,这项刷机过程中最重要的一到 ...
- poj 1741(树的点分治)
Tree Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dis ...
- bzoj3687简单题(dp+bitset优化)
3687: 简单题 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 861 Solved: 399[Submit][Status][Discuss] ...
- SpringCloud 之 Fegin —— 发送GET、POST请求以及文件上传
由于项目需要调用其他微服务的数据,首先想到的就是写一个http网络请求的工具类,但是想到在之前看springCloud的时候里面有这个Fegin可以实现,就顺便实践一下,虽然过程有点坎坷,好在都顺利解 ...
- tp3.2 复合查询or
tp3.2 复合查询or $where['goods_name'] = array("like","%$q%");$where['goods_sn'] = ar ...
- TopK代码
Hash表 #ifndef _HASH_H #define _HASH_H #include<string.h> #include<stdio.h> class HashTab ...
- JavaScript 关于DOM的事件操作
一.JavaScript的组成 JavaScript基础分为三个部分: ECMAscript:JavaScript的标准语法.包括变量,表达式,运算符,函数,if语句,for语句等. DOM:文档对象 ...
- Android中ImageView的属性
资源使用 Android 中支持三种格式的位图文件:.png(首选), .jpg(可接受),.gif(不建议) 为什么首推 PNG 呢? 官网的描述如下: 注:在构建过程中,可通过 aapt 工具自动 ...