您的位置:首页 > 运维架构

TopCoder 250 points 18-SRM 152 DIV 2 167.05/250 66.82%

2013-06-02 18:53 387 查看

Problem Statement

The fixed-point theorem is one of those cornerstones of mathematics that reaches towards all disciplines, and oddly enough it is also closely related to the ability of any program to Quine itself (or to print out its own source code). Put simply, the fixed-point
theorem states that with certain restrictions on a real-valued function F, there is always a point such that X=F(X). Taking the fixed-point theorem further, you can show that any function that meets certain restrictions will start to cycle through values if
you keep on feeding it its own output (doing this with programs and their output is one way of producing programs that Quine themselves).

One simple function that does this is the logistic function F(X)=R*X*(1-X) in the interval [0,1] for certain values of R. For example, if you start with the value X=.25 and feed it into F to get a new X, then feed that value into F to get yet another X,
and so on, the values of X that are produced will converge to a small set of values that will eventually repeat forever, called a cycle.

Your program will be given a double R between 0.1 and 3.569 inclusive. Starting with X=.25, generate the first 200,000 iterations of F using the given value of R, which will stabilize values of X. Then generate 1000 more values, and
return the range of these values (highest value - lowest value). In other words, you will be finding the range of the values produced between iterations 200,001 and 201,000 inclusive.

Definition

Class:FixedPointTheorem
Method:cycleRange
Parameters:double
Returns:double
Method signature:double cycleRange(double R)
(be sure your method is public)

Notes

-Don't worry about overflow. With the given values it'll never happen.

Constraints

-R will be a value between 0.1 and 3.569 inclusive.
-R will always be a value such that the process stated above will produce a result accurate to 1e-9 (absolute or relative).

Examples

0)
0.1

Returns: 0.0

At low numbers, there exists only one point in the cycle, so the answer is 0.0.
1)
3.05

Returns: 0.14754098360655865

2)
3.4499

Returns: 0.4175631735867292

3)
3.55

Returns: 0.5325704489850351

4)
3.565

Returns: 0.5454276003030636

5)
3.5689

Returns: 0.5489996297493569

6)
3.00005

Returns: 0.004713996108955176

Make sure you're iterating 200,000 times.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

public class FixedPointTheorem {

public  double cycleRange(double R) {
int n = 0;
double x = 0.25D;
while (n < 2000000) {
x = R * x * (1.0D - x);
n++;
}
double min = 1.0D;
double max = 0.0D;
n = 0;
while (n < 1000) {
x = R * x * (1.0D - x);
if (x < min)
min = x;
if (x > max)
max = x;
n++;
}

return max - min;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: