hdoj-5879-Cure
2016-09-17 20:23
239 查看
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
就是求∑1/(k*k),然后有一个极限值是Pi*Pi/6,然后差不多估算一下,这个极限值的地方,打个表就好了
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
就是求∑1/(k*k),然后有一个极限值是Pi*Pi/6,然后差不多估算一下,这个极限值的地方,打个表就好了
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> using namespace std; double a[120001]; const int maxn=1e6+5; char str[maxn]; void init() { a[1]=1.0; for(int i=2;i<=120000;i++) a[i]=a[i-1]+1.0/i/i; } int main() { init(); //for(int i=100000;i<=120000;i++) //cout << i << " " << a[i] << endl; while(scanf("%s",str)!=EOF) { int len=strlen(str); if(len>6) printf("%.5f\n",a[120000]); else{ int ans=0; for(int i=0;i<len;i++) { ans=ans*10+str[i]-'0'; } if(ans>=120000) printf("%.5f\n",a[120000]); else printf("%.5f\n",a[ans]); } } return 0; }
相关文章推荐
- hdoj 5879 Cure
- hdoj5879Cure
- [HDOJ5879]Cure(求极限,打表)
- hdu 5879 Cure
- 【HDU 5879】Cure(暴力+优化)
- HDU 5879 Cure
- HDU 5879 Cure (数论)
- HDU 5879 Cure(技巧)——2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5879 Cure(数学)
- HDU 5879---cure
- HDU-5879 Cure(精度)(极限)
- HDU 5879 Cure【数论】
- HDU 5879 Cure -2016 ICPC 青岛赛区网络赛
- HDU 5879 - Cure【2016 ACM 区域赛青岛赛区网络赛】
- hdu 5879 Cure 打表
- HDU 5879 Cure (数学)
- HDU-5879-Cure-打表模拟(水)
- hdu 5879 -Cure 暴力打表
- HDU 5879 Cure (2016 ACM/ICPC Asia Regional Qingdao Online 1002)
- hdu 5879 Cure