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): 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

     
     

    大数据量,想到打表预处理+数学|规律

    规律:k大到一定程度,保留五位小数就不变了

    坑:n没有给出范围,意思就是默认无限大。
    RE原因,输入过大
    #include "string"
    #include "cstdio"
    #include "iostream"
    using namespace std;
    #define MAX 120005
    #define LL long long
    double a[MAX]={0.0,1.0};
    void init()
    {
        for(int i=2;i<MAX;i++)
        {
            a[i]=a[i-1]+1.0/i/i;
        }
    }
    int main()
    {
        init();
        int n,len;
        string s;
        while(cin>>s)
        {
            len=s.length();
            if(len>=7){
                printf("1.64493
    ");
            }else
            {
                n=0;
                for(int i=0;i<len;i++){
                    n=n*10+s[i]-'0';
                    if(n>120000)
                    {
                        n=120000;
                        break;
                    }
                }
                printf("%.5f
    ",a[n]);
            }
        }
        return 0;
    }

    打表+极限

  • 相关阅读:
    入门系列4
    入门系列3
    入门系列2
    入门系列1
    sql进阶-筛选库表中数据为空的表
    sql进阶-删除所有的视图
    sql序列(2) sql语句功能表
    sql序列(5)事务
    sql序列(4)存储过程
    KVM虚拟化介绍
  • 原文地址:https://www.cnblogs.com/kimsimple/p/7096758.html
Copyright © 2011-2022 走看看