hdu5879 Cure
题目链接:hdu5879 Cure
题解:用字符串输入。n很大时答案趋近与(π^2)/6。
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 #include<queue> 6 #include<cmath> 7 using namespace std; 8 const int N = 1000010; 9 const double pi = acos(-1.0); 10 char a[N]; 11 double sum[N]; 12 13 int main(){ 14 int i, l, x; 15 for(int i = 1; i < N; ++i) 16 sum[i] = sum[i - 1] + 1.0/i/i; 17 while(~scanf("%s",a)){ 18 l = strlen(a); 19 if(l >= 7)printf("%.5lf\n",pi*pi/6); 20 else{ 21 for(x = i = 0; i < l; ++i) 22 x = 10 * x + a[i] - '0'; 23 printf("%.5lf\n", sum[x]); 24 } 25 } 26 return 0; 27 }