zoukankan      html  css  js  c++  java
  • HDU 5879 Cure

    Cure

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1333    Accepted Submission(s): 440


    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.
     
    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
     
    Source
     
     
     
    解析:一定要注意这句话“The input file is at most 1M.”坑点所在。输入的长度可能达到1e6。这个极限为PI*PI/6,保留5位小数就是1.64493。n达到1000000左右以后,结果就不会再变了。
     
     
     
    #include <cstdio>
    #include <cstring>
    
    const int MAXN = 1e6+5;
    double sum[MAXN];
    char s[MAXN];
    
    void init()
    {
        sum[0] = 0;
        for(int i = 1; i <= 1000000; ++i){
            sum[i] = sum[i-1]+1.0/(i*1.0*i);
        }
    }
    
    int main()
    {
        init();
        while(~scanf("%s", s)){
            int len = strlen(s);
            if(len >= 7){
                printf("1.64493
    ");
                continue;
            }
            int n = 0;
            for(int i = 0; i < len; ++i)
                n = n*10+s[i]-'0';
            printf("%.5f
    ", sum[n]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    新概念4-38
    新概念4-37
    新概念4-36
    新概念4-35
    国史通鉴-03 天下为私 04
    新概念4-34
    西门子 框架断路器 及其他中低压配电设备资料查询
    OPC UA 的本质
    经典Scout添加等时同步设备
    同步报故障解同步启动
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5894036.html
Copyright © 2011-2022 走看看