Va problem 10215 the largest/smallest box... (Max/min box)

Source: Internet
Author: User
// 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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.