标签:code def std fine name fonts TE freopen ==
题意:
求调和级数,但n很大啦。。
解析:
分段打表 每间隔50存储一个数,在计算时 只需要找到离输入的n最近的那个数 以它为起点 开始计算即可
emm。。。补充一下调和级数的运算公式
r为常数,r=0.57721566490153286060651209(r就是欧拉常数)。
看一下这位的博客:https://www.cnblogs.com/weiyuan/p/5737273.html
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define MOD 2018 #define LL long long #define ULL unsigned long long #define maxn 100000000 #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f; double ch[maxn/50+10]; int main() { int T, cnt = 1; double sum = 0; ch[0] = 0; for(int i=1; i<=maxn; i++) { sum += 1/(double)i; if(i % 50 == 0) ch[cnt++] = sum; } int kase = 0; cin>> T; while(T--) { int n; cin>> n; double m = ch[n/50]; for(int i=n/50*50+1; i<=n; i++) m += 1/(double)i; printf("Case %d: %.10f\n",++kase,m); } return 0; }
Harmonic Number LightOJ - 1234 (分段打表)
标签:code def std fine name fonts TE freopen ==
原文地址:https://www.cnblogs.com/WTSRUVF/p/9189761.html