// The largest/smallest box... (Max/min box) // PC/Ultraviolet IDs: 111306/10215, popularity: A, success rate: average level: 2 // verdict: accepted // submission date: 2011-11-02 // UV Run Time: 0.040 S // copyright (c) 2011, Qiu. Metaphysis # Yeah dot net // [solution] // easy to know, the box volume is: ///V = (L-2 * X) * (W-2 * X) * x = 4 * (x * x)-2 * (L + W) * (x * X) + // L * w * x // The extreme value is required. Obviously, when x = 0 or X = min (L, W)/2, the minimum value is 0, however, the maximum value is not that easy. // you can find it through the derivation of this formula. The derivative of the above formula is: // v '= 12 * x * X-4 * (L + W) * x + L * w // the equation when the derivative is 0. One solution of the equation is the value of X when the maximum value is obtained. It is worth noting that because special // judge is not used in this question, it is wrong to add a small constant to the result to AC, but to add a small constant // to programming challenges. # Include <iostream> # include <iomanip> # include <cmath> using namespace STD; # define Epsilon (1e-7) int main (int ac, char * AV []) {double L, W; cout. precision (3); cout. SETF (IOs: Fixed | IOs: showpoint); While (CIN> L> W) {cout <(L + w-SQRT (double) (L * l-l * w + W * w)/6.0 + Epsilon; cout <"0.000"; cout <(min (L, W) * 0.5 + epsilon) <Endl;} return 0 ;}