首页 > 代码库 > HDU 5879 Cure

HDU 5879 Cure

打表,预处理。

因为只要保留$5$位小数,所以$n$大于某个数字的时候,答案都是一样的,通过寻找可以发现$n$大约为$2000000$。读入的时候需要用字符串。

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<iostream>using namespace std;typedef long long LL;const double pi=acos(-1.0),eps=1e-6;void File(){    freopen("D:\\in.txt","r",stdin);    freopen("D:\\out.txt","w",stdout);}template <class T>inline void read(T &x){    char c=getchar(); x=0;    while(!isdigit(c)) c=getchar();    while(isdigit(c)) {x=x*10+c-0; c=getchar();}}const int maxn=2000010;double a[maxn];char s[10000010];int get(){    int res=0;    for(int i=0;s[i];i++)        res=res*10+s[i]-0;    return res;}int main(){    for(int i=1;i<=2000000;i++)        a[i]=a[i-1]+1.0/((double)i*(double)i);    while(~scanf("%s",s))    {        int len=strlen(s);        if(len>7) printf("%.5lf\n",a[2000000]);        else        {            int n=get();            if(n>=2000000) n=2000000;            printf("%.5lf\n",a[n]);        }    }    return 0;}

 

HDU 5879 Cure