Light oj 1234 - Harmonic Number
题目链接: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的更多相关文章
- light oj -1245 - Harmonic Number (II)
先举个例子,假如给你的数是100的话,将100/2=50;是不是就是100除100-51之间的数取整为1: 100/3=33;100除50到34之间的数为2,那么这样下去到sqrt(100);就可以求 ...
- LightOJ 1234 Harmonic Number(打表 + 技巧)
http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS Memory ...
- 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 1234 Harmonic Number 调和级数部分和
题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 Sample Input Sample Output Case : Case : ...
- LightOJ - 1234 LightOJ - 1245 Harmonic Number(欧拉系数+调和级数)
Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n ...
- 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 ...
- LightOJ1245 Harmonic Number (II) —— 规律
题目链接:https://vjudge.net/problem/LightOJ-1245 1245 - Harmonic Number (II) PDF (English) Statistics ...
随机推荐
- 《分销系统-原创第一章》之“多用户角色权限访问模块问题”的解决思路( 位运算 + ActionFilterAttribute )
此项目需求就是根据给用户分配的权限,进行相应的权限模块浏览功能,因为项目不是很大,所以权限没有去用一张表去存,我的解决思路如下,希望大家给点建议. 数据库用户表结构如下: 数据库表梳理: BankUs ...
- [反汇编练习] 160个CrackMe之015
[反汇编练习] 160个CrackMe之015. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- c & c++中static的总结
static 修饰的三种作用 (1) 静态局部变量 (2) 模块内的全局变量.函数,不可以被其他模块访问 (3) 类的静态成员 其中(3)只在c++中有. (1) 静态局部变量.局部变量一般在函数体内 ...
- POJ:最长上升子序列
Title: http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 ...
- Hide Xcode8 strange log.
Product > Scheme > Edit Scheme Environment Variables set OS_ACTIVITY_MODE = disable
- poj 3694 Network
题意: 添加每条新连接后网络中桥的数目// 超时 先放着了 ,下次改//早上这代码超时了 下午改了,代码在下面#include <iostream> #include <algori ...
- 组以逗号分隔的子串及跨平update join
下列语句可以对组以逗号分隔的子串 set @device_cd_array += ', ' set @device_cd_array += @nodeid ,, '') update时要join表要先 ...
- 确实是非常实用的Ubuntu命令
1 文件管理 # ls ls -a 列出当前目录下的所有文件,包括以.头的隐含文件 文件管理 # ls ls-l或ll 列出当前目录下文件的详细信息 文件管理 # pwd pwd查看当前所在目录的绝对 ...
- Winfrom 开发系统导航菜单
先上图看效果在说. 效果图如上,在Web中这个一点难度都没有,几行Css+JS就搞定了.但是在Winfrom中.本来就是半杯水的水准,想做这个个导航菜单,发现真难找,找了很多都不合胃口,只能自己写个了 ...
- [Everyday Mathematics]20150114
设 $a_0$, $d$ 给定, $a_k=a_0+kd$, $k=0,1,\cdots,n$. 试求如下 $n+1$ 阶行列式的值: $$\bex \sev{\ba{ccccc} a_0&a ...