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

Description

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

In this problem, you are given n, you have to find Hn.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 108).

Output

For each case, print the case number and the nth harmonic number. Errors less than 10-8 will be ignored.

Sample Input

12

1

2

3

4

5

6

7

8

9

90000000

99999999

100000000

Sample Output

Case 1: 1

Case 2: 1.5

Case 3: 1.8333333333

Case 4: 2.0833333333

Case 5: 2.2833333333

Case 6: 2.450

Case 7: 2.5928571429

Case 8: 2.7178571429

Case 9: 2.8289682540

Case 10: 18.8925358988

Case 11: 18.9978964039

Case 12: 18.9978964139

题意:t组数据,每组一个n 求 1+1/2+1/3+1/4 ......+1/n的和

方法:打表 每100个存一个,不够100的跑一趟

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
#define N 1001010
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
double sum[N];
void init()
{
sum[0]=0;
sum[1]=1.0;
double ans=1.0;
for(int i=2;i<=100000009;i++)
{
ans+=1.0/(i*1.0);
if(i%100==0)
sum[i/100]=ans; }
}
int main()
{
init();
int t,l,con=1;
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
l=n/100;
double ans=sum[l];
for(int i=l*100+1;i<=n;i++)
ans+=1.0/(i*1.0);
printf("Case %d: %.10f\n",con++,ans);
}
return 0;
}

1 。 LightOJ 1234 打表法(数据太大,把数据缩小100倍)的更多相关文章

  1. 解决持久化数据太大,单个节点的硬盘无法存储的问题;解决运算量太大,单个节点的内存、CPU无法处理的问题

    需要学习的技术很多,要自学新知识也不是一件容易的事,选择一个自己比较感兴趣的会是一个比较好的开端,于是,打算学一学分布式系统. 带着问题,有目的的学习,先了解整体架构,在深入感兴趣的细节,这是我的计划 ...

  2. ireport报表制作, 当一个字段显示的数据太多时(数据过长),则需要自动换行

    1.当一个字段显示的数据太长,一个表格放不下,则需要自动换行,选中要更改的表格(要显示动态内容的字段),设置属性Stretch with overflow 为钩选状态. 未勾选之前: 勾选之后: 2. ...

  3. PDF太大怎么办?缩小PDF的4种常用方法

    PDF太大怎么变小?我们在平时学习或生活中经常需要上传或提交一些资料,现在网站都是默认需要提交PDF格式的电子文档,有时提交资料会提示超过系统大小,如何才能使PDF缩小呢? 一.在线压缩 首先搜索sp ...

  4. Zabbix的history相关数据表数据太大,执行表分区操作过程

    一.查询zabbix数据库大小 mysql> select table_schema, concat(truncate(sum(data_length)/1024/1024,2),' mb') ...

  5. MySQL数据单个数据太大,导入不进去

    mysql导入数据,navicat报错: MySQL server has gone away Table Restored: act_ge_bytearray Rolling back... Fin ...

  6. POST提交数据太大

    2018.4.8号更新 其实后来最终的解决方案是修改服务器的配置文件. POST数据按道理说是没有大小限制的,只是取决于浏览器或服务器的配置,tomcat的解决方式参考方案2. ----------- ...

  7. JSON 请求太大,无法反序列化。

    在post请求中数据太大导致报500错误.错误提示 JSON 请求太大,无法反序列化. 在config中加 <system.web.extensions> <scripting> ...

  8. LightOJ 1234 Harmonic Number (打表)

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

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

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

随机推荐

  1. OS X 10.9 Mavericks 安装 thrift 0.9.1

    通过Homebrew安装的时候,编译会报错.查了一下资料,原来是10.9系统默认使用的libc++的库,而且移除了C++ 11标准前tr库,所以编译存在问题.且笔者使用的时候,brew安装只支持到0. ...

  2. ubantu 安装mysql

    sudo apt-get install mysql-server mysql-client

  3. QWT6.0.1+win7下安装说明

    A) 简介 1.QWT是一个基于LGPL版权协议的开源项目, 可生成各种统计图.它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或 ...

  4. linux之history

    1.使用HISTTIMEFORMAT在历史中显示TIMESTAMP 通常情况下,当你在命令行中键入history时,终端中将显示你刚输入的命令及其编号.如果出于审查命令的目的,和命令一起显示时间戳将会 ...

  5. JS后退, JS返回上一页, JS返回下一页

    Javascript 返回上一页: 1. history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.fo ...

  6. C语言中将数字转换为字符串的方法

    C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串.以下是用itoa()函数将整数转换为字符串的一个例子: # include <stdio. h># ...

  7. Cows

    Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can ...

  8. 1.5.1 Analyzers,Tokenizers,Filters概述

    字段分析器(Analyzers)即用于文档索引也用于查询.一个分析器检查字段的文本,并生成一个token流.分析器可能是一个单独的类,也可能是一系列的tokenizer和filter的组合. 分词器把 ...

  9. Timed Code

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  10. ios 加载本地html css文件 ps:css和html必须在同一文件夹下面

    NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; ...