Numerical Summation of a Series
Time Limit: 10 Seconds Memory Limit: 32768 KB Special Judge
Produce a table of the values of the series
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=0000%2F1007%2F1007-1.gif)
for the 2001 values of x, x= 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\n", 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
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=0000%2F1007%2F1007-2.gif)
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.
![](http://acm.zju.edu.cn/onlinejudge/showImage.do?name=0000%2F1007%2F1007-3.gif)
题意
给出式子 ,输出x=0.000~x=2.000时的结果。要求保留到小数点后12位
思路
数学题,可以首先根据题目得到,利用这个条件对题目中的式子进行化简:
化简结束后,可以看出对求值是本题的关键
因为当k大到一定值的时候,,(百度看了大佬们的题解后,当k>=20000时可以看做k,这个k的值应该不是唯一的,在不超时的情况下足够大就行)。所以可以对20000项之后进行累加,累加到一个很大的数就行了(比如100W)即计算
的值。然后对于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\n",k,_);
}
return 0;
}