zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    软件架构学习小结
    Azure编程笔记(1):序列化复杂类型的TableEntity字段
    目标检測的图像特征提取之(一)HOG特征
    Gmail POP3设置
    MP3的频率、比特率、码率与音质的关系
    Oracle Dataguard 介绍
    【Github教程】史上最全github用法:github入门到精通
    Xcode6在10.9.4上面crash解决
    OpenCV 编程简单介绍(矩阵/图像/视频的基本读写操作)
    调用ShellExecute所须要头文件
  • 原文地址:https://www.cnblogs.com/Friends-A/p/10324364.html
Copyright © 2011-2022 走看看