• ZOJ 1007:Numerical Summation of a Series(数学)


    Numerical Summation of a Series


    Time Limit: 10 Seconds      Memory Limit: 32768 KB      Special Judge


    Produce a table of the values of the series

    Equation 1

    for the 2001 values of xx= 0.000, 0.001, 0.002, ..., 2.000. All entries of the table must have an absolute error less than 0.5e-12 (12 digits of precision). This problem is based on a problem from Hamming (1962), when mainframes were very slow by today's microcomputer standards.

    Input

    This problem has no input.

    Output

    The output is to be formatted as two columns with the values of x and y(x) printed as in the C printf or the Pascal writeln.

    printf("%5.3f %16.12f
    ", x, psix )		writeln(x:5:3, psix:16:12)
    

    As an example, here are 4 acceptable lines out of 2001.

    0.000   1.644934066848
    ...
    0.500   1.227411277760
    ...
    1.000   1.000000000000
    ...
    2.000   0.750000000000
    

    The values of x should start at 0.000 and increase by 0.001 until the line with x=2.000 is output.

    Hint

    The problem with summing the sequence in equation 1 is that too many terms may be required to complete the summation in the given time. Additionally, if enough terms were to be summed, roundoff would render any typical double precision computation useless for the desired precision.

    To improve the convergence of the summation process note that

    Equation 2

    which implies y(1)=1.0. One can then produce a series for y(x) - y(1) which converges faster than the original series. This series not only converges much faster, it also reduces roundoff loss.

    This process of finding a faster converging series may be repeated to produce sequences which converge more and more rapidly than the previous ones.

    The following inequality is helpful in determining how may items are required in summing the series above.

    Equation 3

    题意

    给出式子varphi (x)=sum ^{infty }_{k=1}dfrac {1}{kleft( k+x
ight) } ,输出x=0.001~x=2.000时的结果。要求保留到小数点后12位

    思路

    数学题,可以首先根据题目得到varphi (x)=1,利用这个条件对题目中的式子进行化简:

    varphi (x)=varphi (x)-varphi (1)+1

    varphi (x)=sum ^{infty }_{k=1}dfrac {1}{kleft( k+x
ight) }-sum ^{infty }_{k=1}dfrac {1}{kleft( k+1
ight) }+1

    varphi (x)=left( 1-x
ight) sum ^{infty }_{k=1}dfrac {1}{kleft( k+x
ight) left( k+1
ight) }+1

    化简结束后,可以看出对sum ^{infty }_{k=1}dfrac {1}{kleft( k+x
ight) left( k+1
ight) }求值是本题的关键

    因为当k大到一定值的时候,k+xapprox k,(百度看了大佬们的题解后,当k>=20000时可以看做k,这个k的值应该不是唯一的,在不超时的情况下足够大就行)。所以可以对20000项之后进行累加,累加到一个很大的数就行了(比如100W)即计算sum ^{1e6 }_{k=20000}dfrac {1}{k*k*left( k+1
ight) }的值。然后对于1~20000之内的和用循环求出即可

    AC代码

    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <math.h>
    #include <limits.h>
    #include <map>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <set>
    #include <string>
    #define ll long long
    #define ull unsigned long long
    #define ms(a) memset(a,0,sizeof(a))
    #define pi acos(-1.0)
    #define INF 0x7f7f7f7f
    #define lson o<<1
    #define rson o<<1|1
    const double E=exp(1);
    const double eps=1e-12;
    const double maxn=1e6+10;
    const int mod=1e9+7;
    using namespace std;
    int main(int argc, char const *argv[])
    {
    	double res=0.0;
    	double _;
    	for(double i=20000.0;i<=maxn;i+=1.0) 
    		res+=1.0/(i*i*(i+1));
    	for(double k=0.000;k<=2.0005;k+=0.001)
    	{
    		_=res;
    		for(double i=20000;i>=1;i--)
    		{
    			_=_+1.0/(i*(i+k)*(i+1));
    		}	
    		_=_*(1-k);
    		_+=1;
    		printf("%5.3f %16.12f
    ",k,_);
    	}
    	return 0;
    }
  • 相关阅读:
    redis05
    redis04
    redis03
    redis02
    C++编程学习(九)this指针&友元函数
    C++编程学习(八)new&delete动态内存分配
    ROS大型工程学习(二) 怎么阅读大型工程
    计算机操作系统学习(一) Linux常用指令(随时更新)
    ROS大型工程学习(一) 必须了解的基本文件
    单片机学习(一) 中断、定时器、优先级的一些理解
  • 原文地址:https://www.cnblogs.com/Friends-A/p/10324364.html
Copyright © 2020-2023  润新知