您的位置:首页 > 其它

LightOJ 1234 Harmonic Number 分布式打表

2016-08-30 23:20 295 查看
分布均匀的打表可以有效提高速度。

输出使用%f,输入使用%lf。

题目链接:http://acm.hust.edu.cn/vjudge/problem/26945

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<vector>
#include<fstream>
#include<list>
using namespace std;

#define ms(s) memset(s,0,sizeof(s))
typedef unsigned long long ULL;
typedef long long LL;

const int INF = 0x3fffffff;

double num[1000010];

int main()
{
//    freopen("F:\\input.txt","r",stdin);
//    freopen("F:\\output.txt","w",stdout);
//    ios::sync_with_stdio(false);

ms(num);
int t;
int n;
double ans = 0;
for(int i = 1; i <= 100000000; ++i){
ans += 1.0/(double)i;
if(i%100 == 0)
num[i/100] = ans;
}
scanf("%d",&t);
for(int cas = 1; cas <= t; ++cas){
scanf("%d",&n);
ans = num[n/100];
for(int i = n/100*100+1; i <= n; ++i){
ans += 1.0/(double)i;
}
printf("Case %d: %.10f\n",cas,ans);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: