#C12665. Hill Climbing Optimization on a Quadratic Function

    ID: 42117 Type: Default 1000ms 256MiB

Hill Climbing Optimization on a Quadratic Function

Hill Climbing Optimization on a Quadratic Function

You are tasked with implementing a hill climbing algorithm to find the maximum value of a quadratic function on a given interval. The function is defined as \( f(x) = -x^2 + 6x - 5 \). The algorithm should start at a given point within the interval [0, 5] and move in steps of 0.1, checking both left and right neighbors until a peak is found.

Specifically, starting from an initial point x, compute the neighbors at \( x-0.1 \) and \( x+0.1 \) (making sure they abide by the boundaries). Update the current point if one of the neighbors has a higher function value. Repeat until no neighbor offers an improvement. Finally, output the found optimal value and its corresponding function value formatted to 6 decimal places.

inputFormat

The input is provided through standard input (stdin) as a single floating point number, representing the starting point.

Input Format:

[start]

Note: The starting point is guaranteed to be a real number.

outputFormat

The output should be written to standard output (stdout) as two floating point numbers separated by a space. The first number is the point \( x \) where the function attains a (local) maximum, and the second number is the maximum value \( f(x) \). Both numbers must be printed with 6 decimal places.

Output Format:

[x] [f(x)]
## sample
2.5
3.000000 4.000000