"BZOJ2876" "NOI2012" Riding Sichuan-Tibet Lagrange Multiplier,

Source: Internet
Author: User

Exercises


I don't know why I use this, but it does.

Well, the V here has a monotonous relationship with the result, so you can get a two-point solution ...


Shallow comprehension of Lagrange equation (possibly wrong):

Set a λ to two points and use this value to calculate the derived variable, and then check whether the limit is met

So get the correct argument and then the solution.


The equation is Ⅰ, while the formula Ⅱ is the V-variable biasing function of the equation, and Ⅲ is a small deformation.

(Image from Http://txhwind.blog.163.com/blog/static/203524179201313112815690/)


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 10100# Define EPS 1e-9#define inf 1e9using namespace std;int n;double k[n],v1[n],v[n],s[n];void calc (double lambda)//based on this λ to calculate the speed, { for (int i=0;i<n;++i) {double L=max (0.0,v1[i]), r=1e9;for (int c=0;c<130;++c) {double mid= (l+r) *0.5; ((2.0*lambda* k[i]*mid*mid* (Mid-v1[i]) <1.0) l:r) =mid;} V[i]=l;}} int main () {//freopen ("test.in", "R", stdin), int i,j,k;double e;scanf ("%d%lf", &n,&e); for (I=0;i<n;++i) scanf ("%lf%lf%lf", S+i,k+i,v1+i);d ouble l=0,r=1e9;for (k=90;k--;) {double mid= (l+r) *0.5,sum=0;calc (mid), and//based on this λ to calculate the speed, for (I=0;i<n;++i) sum+=k[i]* (V[i]-v1[i]) * (V[i]-v1[i]) *s[i]; You can then know whether the speed is consistent, (sum<e?r:l) =mid;} Double Ans=0;for (i=0;i<n;++i) ans+=s[i]/v[i]; Now V is a set of compliant V, printf ("%lf\n", ans); return 0;}


"BZOJ2876" "NOI2012" Riding Sichuan-Tibet Lagrange Multiplier,

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.