题目链接:http://lightoj.com/volume_showproblem.php?problem=1234

给你一个数n,让你求

这个要是直接算的话肯定TLE,要是用1e8的数组预处理存储答案也一定MLE。

所以我用1e6的数组存储每100个数的答案,然后每次给你n的时候顶多算99次。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 1e8;
double ans[] , temp;
int cont;
int main()
{
ans[] = cont = temp = ;
for(int i = ; i <= MAXN ; i++) {
temp = temp + 1.0 / i;
if(i % == )
ans[++cont] = temp;
}
int t , n;
scanf("%d" , &t);
for(int ca = ; ca <= t ; ca++) {
scanf("%d" , &n);
double res = ans[n / ];
for(int i = n / * + ; i <= n ; i++) {
res += 1.0 / i;
}
printf("Case %d: %.10f\n" , ca , res);
}
}

Light oj 1234 - Harmonic Number的更多相关文章

  1. light oj -1245 - Harmonic Number (II)

    先举个例子,假如给你的数是100的话,将100/2=50;是不是就是100除100-51之间的数取整为1: 100/3=33;100除50到34之间的数为2,那么这样下去到sqrt(100);就可以求 ...

  2. LightOJ 1234 Harmonic Number(打表 + 技巧)

    http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS     Memory ...

  3. LightOJ 1234 Harmonic Number

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

  4. LightOJ 1234 Harmonic Number (打表)

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

  5. LightOJ 1234 Harmonic Number 调和级数部分和

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 Sample Input Sample Output Case : Case : ...

  6. LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)

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

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

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

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

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

  9. LightOJ1245 Harmonic Number (II) —— 规律

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

随机推荐

  1. MySQL学习笔记一

    MySQL 学习笔记 一 一.数据库简单介绍 1. 按照数据库的发展时间顺序,主要出现了以下类型数据库系统: Ø 网状型数据库 Ø 层次型数据库 Ø 关系型数据库 Ø 面向对象数据库 上面4中数据库系 ...

  2. c#(.net) 导出 word表格

    做了差不多一周的导出Word,现在把代码贴出来   : ExportWord.cs using System; using System.Collections.Generic; using Syst ...

  3. UVa 11584 Partitioning by Palindromes

    题意: 给出一个字符串,求最少能划分成多少个回文子串. 分析: d[i] = min{d[j] + 1 | s[j+1]...s[i]是回文串} d[i]表示前 i 个字符最少能分割的回文子串的个数 ...

  4. 【C#学习笔记】结构体使用

    using System; namespace ConsoleApplication { struct _st { public string name; public int age; } clas ...

  5. 庖丁解牛-----Live555源码彻底解密(RTP解包)

    Live555 客户端解包 以testRTSPClient.cpp为例讲解: Medium<-MediaSource<-FramedSource<-RTPSource<-Mul ...

  6. Vagrant搭建Ubuntu-JavaEE开发环境——Tomcat+JDK+MySQL+dubbo+测试

    Vagrant搭建(Tomcat8+JDK7+MySQL5+dubbo) JDK 1.下载jdk 2.解压JDK tar -xzvf jdk-7u79-linux-x64.tar.gz 3.设置环境变 ...

  7. binlog/relay_log的清理

    http://www.yuminstall.com/how-to-remove-mysql-relay-log.html CHANGE MASTER TO changes the parameters ...

  8. YUV采样及存储格式

    YUV,分为三个分量,“Y”表示明亮度(Luminance或Luma),也就是灰度值:而“U”和“V” 表示的则是色度(Chrominance或Chroma),作用是描述影像色彩及饱和度,用于指定像素 ...

  9. Ubuntu 出现 apt-get问题的解决方法

    ubuntu 10.10 sudo apt-get update 404  Not Found or W: Failed to fetch http://cn.old-releases.ubuntu. ...

  10. adb remount 失败remount failed: Operation not permitted

    1. 进入shell adb shell 2. shell下输入命令 shell@android:/ $ sushell@android:/ # mount -o rw,remount -t yaff ...