Bzoj 2876 NOI2012 Cycling Sichuan-Tibet two points + mathematical algorithm

Source: Internet
Author: User

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

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.