您的位置:首页 > 其它

HDU5879(打表)

2016-09-17 20:08 351 查看

Cure

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 293    Accepted Submission(s): 96


Problem Description

Given an integer n, we only want to know the sum of 1/k2 where k from 1 to n.  

 

Input

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.
 

 

Output

The required sum, rounded to the fifth digits after the decimal point.  

 

Sample Input

1 2 4 8 15  

 

Sample Output

1.00000 1.25000 1.42361 1.52742 1.58044  

 

Source

2016 ACM/ICPC Asia Regional Qingdao Online   n没有给出范围,意思就是默认无限大。。。。。比赛时被坑了,不停RE。
//2016.9.17
#include <iostream>
#include <cstdio>

using namespace std;

double sum[54000];

int main()
{
int n;
double ans;
ans = 0;
sum[0] = 0;
for(int i = 1; i <= 53000; i++)
{
ans += (1.0/i)*(1.0/i);
sum[i] = ans;
}
string s;
while(cin>>s)
{
int len = s.length();
n = 0;
for(int i = 0; i < len; i++)
{
n = n*10+s[i]-'0';
if(n > 120000)break;
}
if(n >= 110291)ans = 1.64493;
else if(n >= 52447)ans = 1.64492;
else ans = sum
;
printf("%.5lf\n", ans);
}

return 0;
}

 

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