• HDU5879(打表)


    Cure

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


    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

     
    n没有给出范围,意思就是默认无限大。。。。。比赛时被坑了,不停RE。
     1 //2016.9.17
     2 #include <iostream>
     3 #include <cstdio>
     4 
     5 using namespace std;
     6 
     7 double sum[54000];
     8 
     9 int main()
    10 {
    11     int n;
    12     double ans;
    13     ans = 0;
    14     sum[0] = 0;
    15     for(int i = 1; i <= 53000; i++)
    16     {
    17         ans += (1.0/i)*(1.0/i);    
    18         sum[i] = ans;
    19     }
    20     string s;
    21     while(cin>>s)
    22     {
    23         int len = s.length();
    24         n = 0;
    25         for(int i = 0; i < len; i++)
    26         {
    27             n = n*10+s[i]-'0';
    28             if(n > 120000)break;
    29         }
    30         if(n >= 110291)ans = 1.64493;
    31         else if(n >= 52447)ans = 1.64492;
    32         else ans = sum[n];
    33         printf("%.5lf
    ", ans);
    34     }
    35 
    36     return 0;
    37 }
  • 相关阅读:
    iOS电商类App研发学习总结
    Swift4.0复习闭包
    Swift4.0复习函数
    Swift4.0复习Optional
    SQL面试题
    sql(join on 和where的执行顺序)
    算法四:回溯和分支界定
    算法三:贪婪算法
    编程之美2.11:寻找最近的点对
    编程之美2.5:寻找最大的K个数
  • 原文地址:https://www.cnblogs.com/Penn000/p/5879533.html
Copyright © 2020-2023  润新知