The main topic: given N-segment road, each length of Si, if the road at the speed of the vi at a constant pace, then the physical consumption of ki* (Vi-v ' i) ^2*si, in the case of the maximum speed without exceeding the physical limit
I bought a watch last year--to go online Baidu for half a day three times the root formula of the equation only to find that the function is incremental--Baidu encyclopedia write what nm broken play should--
It seems to be not clear--Ms just know the Lagrange multiplier method can almost understand the problem--
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 10100# Define INF 1e9#define EPS 1e-12using namespace Std;int n;double e,s[m],k[m],v[m],x[m];d ouble Calculate (double lambda) { Double temp=0;for (int i=1;i<=n;i++) {double L=max (0.0,v[i]), R=inf;while (r-l>eps) {double mid= (l+r)/2;if ( lambda*k[i]*mid*mid* (Mid-v[i]) >1) R=mid;else L=mid;} x[i]= (l+r)/2;temp+=k[i]* (X[i]-v[i]) * (X[i]-v[i]) *s[i];} return temp;} void Bisection () {double L=0,r=inf;while (r-l>eps) {double mid= (l+r)/2;if (Calculate (mid) >=e) L=mid;else R=mid;} int main () {int i;cin>>n>>e;for (i=1;i<=n;i++) scanf ("%lf%lf%lf", &s[i],&k[i],&v[i]); Bisection ();d ouble ans=0;for (i=1;i<=n;i++) ans+=s[i]/x[i];p rintf ("%.10lf\n", ans); return 0;}
Bzoj 2876 NOI2012 Cycling Sichuan-Tibet two points + mathematical algorithm