ZOJ1007.Numerical Summation of a Series

6 篇文章 0 订阅

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=7

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\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


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

 


题意:给出公式 f(x) = sigma( k(k+x)^-1)  //k = 1..inf.  求出f(0.000), f(0.001), f(0.002), ... , f(2.000)这2001个值..

大致思路:打表不能^^k,其实后面的Hint已经说给我们听怎么做了。。f(x) - f(1) = sigma((1-x) / (k * ( k+1 ) * (k+x))),,用这条公式算收敛得会比较快..根据第三条公式知,f(x)-f(1) < sigma(k^-3)<int^1(x^-3dx) = -0.5x^-2...所以k取1到1e6,后面的可以忽略不计..不过因为1e6会超是.我就取1到5e5。还一个优化就是若x>=1, f(x) = f(x-1)*(x-1)/x+x^-2...


#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAXN 500000
#define eps (1e-8)
#define INF 1000000000
#define abs(x) ( (x) > 0? (x): -(x) )
#define sqr(x) ((x) * (x))
#define MAX(a, b) ((a) > (b)? (a): (b))
#define MIN(a, b) ((a) < (b)? (a): (b))

typedef long long LL;

double psix[3000];

template <typename T> void myswap( T &x, T &y ) { T temp = x; x = y; y = temp; }

int main()
{
    double ans = 0;
    for ( int j = 0; j <= 2000; ++j )
    {
        double x = j / 1000.0;
        if ( j < 1000 )
        {
            ans = 0;
            for ( int i = 1; i < MAXN; ++i )
                ans += ( 1 - x ) / ( ( i + x ) * i * ( i + 1 ) );
                /*
                 * 上面的公式改成 ans += ( 1 - x ) / ( i + x ) / i / ( i + 1 );会慢很多,因为除法比乘法慢。
                 */
            ans = ans + 1;
        }
        else
            ans = psix[j - 1000] * ( ( x - 1 ) / x ) + 1.0 / sqr(x);
        printf( "%5.3lf %16.12lf\n", x, ans );
        psix[j] = ans;
    }
    return 0;
}


P.S.  图片上传有问题,本人比较懒,建议还是上去zoj看原题。

ZJU_Main 主页 下一页 ZJU 题型分类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有比较简单的好算法 1307 Packets 简单题,不过也蛮经典的…… 1312 Prime Cuts 简单题 1334 Basically Speaking 简单题 1337 Pi 简单题 1342 Word Index 简单题 1349 Four Quarters 简单题 1350 The Drunk Jailer 简单题 1352 Number Base Conversion 简单题 1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题…… 1354 Extended Lights Out 简单题 1362 Game Prediction 简单题 1365 Mileage Bank 简单题 1382 A Simple Task 简单题 1383 Binary Numbers 简单题 1403 Safecracker 简单题 1408 The Fun Number System 简单题 1486 Color the Tree 简单题 1487 Playing Cards 简单题 1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就可以过…… 1503 One Person "The Price is Right" 简单题,POI Eggs的翻版 1512 Water Treatment Plants 简单题,组合计数 1526 Big Number 简单题,不过O(1)和O(n)还是有区别的:) 1529 Enigmatic Travel 简单题,不过个人感觉题目描述很令人费解 1530 Find The Multiple 简单题 1537 Playing with a Calculator 简单题 1577 GCD & LCM 简单题,分区联赛的题…… 1005 Jugs 简单题 1543 Stripies 简单题 1569 Partial Sums 简单题 1062 Trees Made to Order 简单题 1070 Bode Plot 简单题 1073 Round and Round We Go 简单题,142857,我喜欢^_^ 1078 Palindrom Numbers 简单题 1086 Octal Fractions 简单题 1199 Point of Intersection 简单题 1104 Leaps Tall Buildings 简单题 1110
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值