1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #include<bits/stdc++.h> using namespace std; const double eps=1e-12; double s; int a,b,c; double x,y,z; double ff(double x,double y) { double z=s-x-y; double ans=0; if(z!=0) ans=c*log(z); else if(z==0&&c!=0) ans=0; if(y!=0) ans+=b*log(y); else if(y==0&&b!=0) ans=0; return ans; } double f(double x) { double low=0.0; double up=s-x; double m1,m2; int tot=0; while(tot<=100) { tot++; m1=low+(up-low)/3.0; m2=up-(up-low)/3.0; if(ff(x,m1)+eps<=ff(x,m2)) low=m1; else up=m2; } y=(m1+m2)/2; double ans=ff(x,y); if(x!=0) ans+=a*log(x); else if(x==0&&a!=0) ans=0; return ans; } double three_devide(double low,double up) { double m1,m2; int tot=0; while(tot<=100) { tot++; m1=low+(up-low)/3.0; m2=up-(up-low)/3.0; if(f(m1)+eps<=f(m2)) low=m1; else up=m2; } return (m1+m2)/2; } int main() { scanf("%lf",&s); scanf("%d%d%d",&a,&b,&c); x=three_devide(0.0,s); z=f(x); z=s-x-y; printf("%.10f %.10f %.10f",x,y,z); return 0; }
|