Codeforces Round #118 (Div. 1) A Mushroom Scientists (多元函数极值问题+拉格朗日乘数法)

来源:互联网 发布:php 扩展开发 编辑:程序博客网 时间:2024/05/21 07:57

题目链接:Codeforces Round #118 (Div. 1) A Mushroom Scientists

题意:提炼出来就是求f(x,y,z)=x^a*y^b*z^b,这个三元函数在(0<=x,y,z,x+y+z<=s)的区域内的最值。

思路:

更严格的还要证明在边界所取到的值比极值要小。

注意:%.10lf注意看题目的output


AC代码:

#include <stdio.h>int main(){    int s;    int a,b,c;    double x,y,z,p;    while(scanf("%d",&s)!=EOF){        scanf("%d %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;}


4 0