Cure

来源:互联网 发布:单链表反转java 编辑:程序博客网 时间:2024/06/05 16:16

这里写图片描述


解法:其实发现读入超过一个很大的数之后小数点后5位不会发生改变的了,然后预处理前面的就好了。


#include <stdio.h>#include <stdlib.h>#include <string.h>#include <iostream>using namespace std;const long long maxn = 1000000;double ans = 0;double a[maxn+10];long long n;char s[10000000];int main() {    a[0] = 0.0;    ans = 0;    for (int i = 1; i <= maxn; i++) {        ans = ans+1.0/double(double(i)*double(i));        a[i] = ans;    }    while (scanf("%s", &s) != EOF) {        if (strlen(s) > 7) n = maxn;        else {            sscanf(s, "%lld", &n);        }        if (n > maxn) n = maxn;        printf("%.5lf\n", a[n]);    }}
0 0
原创粉丝点击