UberOA #25
Convex Function Minimization
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchBits & Math
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.
Input
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.
Output
For each query, output one line with the minimizer x, which must have six decimal places.
Example 1
Input:
3
1 -4 7 0 10
1 2 1 0 5
2 -8 1 3 10
Output:
2.000000
0.000000
3.000000
Example 2
Input:
1
1000000 1 0 -1 1
Output:
-0.000001
Example 3
Input:
1
3 -2 5 0 1
Output:
0.333333
Example notes
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.
Editorial
Loading solution…