http://www.lydsy.com/JudgeOnline/problem.php?id=2876
Lagrange Multiplier method: F ' + into G ' =0,f is the derivative of the function, and G is the derivative of the limiting condition.
Idea: e=σki*si* (Vi-vi ') ^2, greedy know, when e=eu, can get the optimal solution.
We assume that the function F=σsi/vi, limit g=σki*si* (Vi-vi ') ^2=e
According to the Lagrange multiplier method, F ' + into g ' = 0,
G ' =2*ki*si* (Vi-vi ')
F ' =-si/(vi^2)
Can get-si/(vi^2) +2* into *ki*si* (VI-VI ') =0
That is, *ki* (vi^2) * (VI-VI ') =1
Due to the negative correlation with VI, and the VI is positively correlated with e, so into the negative correlation with e, so that satisfies the monotone, two-part value, to determine whether the solution is equal to E
In *ki* (vi^2) * (VI-VI ') -1=0, (vi^2) * (VI-VI ') about VI monotonically increasing (vi>0), you can also find the root of the equation by two points.
1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 Const Doubleeps=1e- A;7 Const Doubleinf=1e9;8 Doubleans[10005],k[10005],v[20005],s[20005],e;9 intN;Ten DoubleCalcintXDoubleMid) { One DoubleL=std::max (0.0, V[x]), r=inf; A while(r-l>EPS) { - DoubleMid= (L+R)/2; - if(mid*mid*2*mid*k[x]* (Mid-v[x])-1>0) r=mid; the ElseL=mid; - } - returnl; - } + DoubleSqrDoublex) { - returnx*x; + } A DoubleWorkDoublemid) { at for(intI=1; i<=n;i++) -ans[i]=Calc (i,mid); - Doubleres=0; - for(intI=1; i<=n;i++) -res+=s[i]*k[i]* (Sqr (v[i]-ans[i])); - returnRes; in } - intMain () { toscanf"%d", &n); scanf ("%LF",&E); + for(intI=1; i<=n;i++){ -scanf"%LF%LF%LF",&s[i],&k[i],&v[i]); the } * DoubleL=0, r=1e9; $ while(r-l>EPS) {Panax Notoginseng DoubleMid= (L+R)/2; - if(mid) >e) l=mid; the ElseR=mid; + } A Doubleans=0; the for(intI=1; i<=n;i++) +ans+=s[i]/Ans[i]; -printf"%.8f\n", Ans); $}
Bzoj 2876 Riding Chuan Zang