2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure
Posted Annetree的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure相关的知识,希望对你有一定的参考价值。
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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
n范围很大,需要用字符串读入
1 #include <iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstring> 6 using namespace std; 7 double a[1000005]; 8 char ch[1000005]; 9 int n; 10 int main() 11 { 12 13 for(int i=1000000;i>=1;i--) 14 a[i]=a[i+1]+1.0/pow((double)i,2.0); 15 16 while(~scanf("%s",&ch)) 17 { 18 int len=strlen(ch); 19 int n=0; 20 for(int i=0;i<len;i++) {n=n*10+ch[i]-‘0‘; if (n>1000000) break;} 21 22 if(n>=1000000) printf("%.5lf\n",a[1]); 23 else printf("%.5lf\n",a[1]-a[n+1]); 24 } 25 return 0; 26 }
以上是关于2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure的主要内容,如果未能解决你的问题,请参考以下文章
2016 ACM/ICPC Asia Regional Shenyang Online
2016 ACM/ICPC Asia Regional Qingdao Online HDU5889
2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure
2016 ACM/ICPC Asia Regional Qingdao Online