HDU 5879 Cure
2016-09-17 22:25
288 查看
Cure
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 580 Accepted Submission(s): 206
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
比赛的时候一直提示runtime error 原来输入是数组,诶,我这个小白被坑上面了。无奈。
代码附上啊:
#include <stdio.h> #include <string.h> double a[1000001]={0}; char b[1000005]; int main() { int i,j,len,n; double sum,tmp; for(i=1;i<=1000000;i++) { tmp=i*1.0; a[i]=a[i-1]+(1.0)/(tmp*tmp); } while(~scanf("%s",b)) { len=strlen(b); n=0; if(len>=7) printf("%.5lf\n",a[1000000]); else { for(j=0;j<len;j++) { n=n*10+b[j]-'0'; } printf("%.5lf\n",a ); } } return 0; }
相关文章推荐
- hdu 5879 Cure 2016ACM/ICPC青岛赛区网络赛1002
- 【HDU 5879】Cure(暴力+优化)
- HDU5879 Cure
- [HDU 5879] Cure (数学+打表)
- hdu 5879 Cure
- hdu 5879 Cure -ICPC网络赛青岛赛区
- hdu_5879_Cure(打表)
- HDU 5879-Cure(1/n^2之和)
- HDU 5879---cure
- hdu 5879 Cure 打表
- hdu 5879 -Cure 暴力打表
- HDU 5879 Cure【数论】
- HDU 5879 Cure -2016 ICPC 青岛赛区网络赛
- HDU 5879 Cure
- HDU 5879 Cure .
- HDU 5879 Cure(技巧)——2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5879 - Cure【2016 ACM 区域赛青岛赛区网络赛】
- HDU-5879-Cure-打表模拟(水)
- HDU 5879 Cure(打表预处理)
- HDU 5879 Cure 2016 ACM/ICPC Asia Regional Qingdao Online 1002