UberOA #25
Convex Function Minimization
估计中等可在线判题
Each query gives a convex quadratic function f(x)=Ax²+Bx+C and a closed interval [left,right]; find the x that minimizes the function value, not the minimum value itself. Round the result to six decimal places; when the true value lies exactly at the midpoint between two six-decimal numbers, either rounding is accepted.
This site's standard input/output is stated explicitly.
输入格式
The first line contains q, followed by q lines of A B C left right. This site's integer protocol: 1≤q≤1000, 1≤A≤10⁶, B/C/left/right are in −10⁶..10⁶, and left≤right.
输出格式
For each query, output one line with the minimizer x, which must have six decimal places.
样例 1
输入:
3
1 -4 7 0 10
1 2 1 0 5
2 -8 1 3 10
输出:
2.000000
0.000000
3.000000
样例 2
输入:
1
1000000 1 0 -1 1
输出:
-0.000001
样例 3
输入:
1
3 -2 5 0 1
输出:
0.333333
样例说明
Example 1: the three unconstrained minimizers are 2, −1, and 2; after restricting to the corresponding intervals, the outputs are 2.000000, 0.000000, and 3.000000. Example 2: the minimizer is −0.0000005, so both −0.000001 and 0.000000 are valid. Example 3: the minimizer is 1/3, so the output is 0.333333.