luogu#P3382. 三分

三分

Background

This problem may have severe precision issues and can be hard to pass on some testdata. The testdata is relatively weak and is for reference only.

Problem Description

As stated, you are given an NN-th degree polynomial. It is guaranteed that within the interval [l,r][l, r] there exists a point xx such that the function is monotonically increasing on [l,x][l, x] and monotonically decreasing on [x,r][x, r]. Find the value of xx.

Input Format

The first line contains a positive integer NN and two real numbers l,rl, r, as described above.

The second line contains N+1N + 1 real numbers, representing the coefficients of the NN-th degree polynomial from highest degree to lowest.

Output Format

Output one line containing a real number, which is the value of xx. Your answer is considered correct if it satisfies either of the following:

  • Your answer xx' has a relative or absolute error not exceeding 10510^{-5} compared to the standard answer xx.
  • The function values corresponding to your answer and the standard answer, that is, f(x)f(x') and f(x)f(x), have a relative or absolute error not exceeding 10510^{-5}.
3 -0.9981 0.5
1 -3 -3 1
-0.41421

Hint

For 100%100\% of the testdata, 6N136 \le N \le 13, the coefficients of the polynomial are in [100,100][-100, 100] with up to 1515 decimal places, l,r10|l|, |r| \le 10 with up to 1515 decimal places, and lrl \le r.

Sample Explanation:

As shown in the figure, the red segment is the graph of the function f(x)=x33x23x+1f(x) = x^3 - 3 x^2 - 3x + 1 on the interval [0.9981,0.5][-0.9981, 0.5].

When x=0.41421x = -0.41421, the graph reaches its highest point, so the function is monotonically increasing on [l,x][l, x] and monotonically decreasing on [x,r][x, r]. Therefore x=0.41421x = -0.41421, and the output is 0.41421-0.41421.

Translated by ChatGPT 5