您的位置:首页 > 其它

HDU5879 Cure

2016-09-21 08:44 363 查看

Cure

[b]Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1264    Accepted Submission(s): 424
[/b]

[align=left]Problem Description[/align]
Given an integer n,
we only want to know the sum of 1/k2
where k
from 1
to n.
 

[align=left]Input[/align]
There are multiple cases.

For each test case, there is a single line, containing a single positive integer
n.

The input file is at most 1M.

 

[align=left]Output[/align]
The required sum, rounded to the fifth digits after the decimal point.
 

[align=left]Sample Input[/align]

1
2
4
8
15

 

[align=left]Sample Output[/align]

1.00000
1.25000
1.42361
1.52742
1.58044

 1000000后的结果都没变化了。
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000010
#define ll long long int
double sum[maxn];
char s[maxn];
int main()
{
ll i;
char c;
for(i = 1;i <= maxn;i++)
sum[i] = sum[i-1]+1*1.0/(i*i);
int len, all;
while(~scanf("%s", s)){
len = strlen(s);
all = 0;
for(i = 0;i < len;i++){
all = all*10 + (s[i]-48);
if(all>=maxn) break;
}
while((c=getchar())!='\n'){
if(all <= maxn) all = all*10 + (c-48);
}
if(all>=maxn) printf("%.5lf\n", sum[maxn]);
else printf("%.5lf\n", sum[all]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu