Codeforces Round #118 (Div. 1) A Mushroom scientists (multivariate function extremum problem + Lagrange multiplier method)

Source: Internet
Author: User

Topic Links: Codeforces Round #118 (Div. 1) A Mushroom scientists

Test instructions: Refinement is to seek f (x, Y, z) =x^a*y^b*z^b, the ternary function in the (0<=x,y,z,x+y+z<=s) region of the maximum value.

Ideas:

Stricter also proves that the value taken at the boundary is smaller than the extremum.

Note:%.10LF look at the output of the topic


AC Code:

#include <stdio.h>int main () {    int s;    int a,b,c;    Double x,y,z,p;    while (scanf ("%d", &s)!=eof) {        scanf ("%d%d", &a,&b,&c);        p=1.0* (a+b+c)/s;if (a+b+c==0) {x=0,y=0,z=0;printf ("%.10lf%.10lf%.10lf\n", X, Y, z); continue;}        x=a/p;        y=b/p;        z=c/p;        printf ("%.10lf%.10lf%.10lf\n", X, Y, z);    } return 0;}


Codeforces Round #118 (Div. 1) A Mushroom scientists (multivariate function extremum problem + Lagrange multiplier method)

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.