hdu_5879_Cure(打表)

题目链接:hdu_5879_Cure

题意:

给你一个n,让你计算1/k2的和,k从1到n。

题解:

因为只保留5位小数,所以打个100W的表,比这个数大的直接输出最后一位就行了

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4 typedef long long ll;
 5 
 6 double a[1000001];
 7 char str[1000001];
 8 int main(){
 9     double ans=0;
10     F(i,1,1000000)ans+=1.0/((double)i*i),a[i]=ans;
11     while(~scanf("%s",str))
12     {
13         int len=strlen(str);
14         if(len>6)printf("%.5lf
",a[1000000]);
15         else 
16         {
17             int tp;
18             sscanf(str,"%d",&tp);
19             printf("%.5lf
",a[tp]);
20         }
21     }
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/bin-gege/p/5887172.html