Advanced Mathematics (Lagrange multiplier method): NOI 2012 Riding Chuan Zang

Source: Internet
Author: User

[NOI2012] Cycling chuan Zang

Input file: bicycling.in output file: bicycling.out Evaluation Plugin
Time limit: 1 s memory limit: MB

NOI2012 Day1

Description

The egg is very keen to challenge oneself, this summer vacation he prepares to ride a bicycle from Chengdu to Lhasa along the Sichuan-Tibet line. Sichuan-Tibet Line has a very beautiful scenery along the way, but there are many obstacles in this way, the road is changeable, and the physical strength of the eggs is very limited, so in the day before the ride to set a good destination, while reasonable distribution of their physical strength is a very important thing.
Since the eggs are equipped with a very good bike, it is assumed that during the ride he is only able to overcome the wind resistance (not affected by the friction of the bicycle itself and the friction of the bicycle and the ground). One day he was going to ride the N-section of the road the road conditions in each paragraph can be regarded as the same: for paragraph I, we give 3 parameters about the road condition Si, Ki, vi ', where SI indicates the length of the road, Ki indicates the wind resistance coefficient of this passage, VI ' indicates the wind speed on this road (indicating that he met the wind in this passage, anti- Which means he will be affected by the headwind). If the speed of the ride at a certain time on this road is V, then he is subjected to a wind resistance of the size F = Ki (V-vi ') ^2 (so that if the length of the distance of s to keep the speed of the ride v constant, then he consumes energy (work) E = Ki (V-vi ') ^2 s).
Set the egg at the beginning of the day the fitness value is Eu, please help him to design a driving plan, so that he in a limited amount of energy within the shortest time to reach the destination. Please tell him the shortest time t is how much.

"Scoring Method"
There is no part of the subject, your program output only and the answer to the gap of not more than 0.000001, to obtain the full score of the test point, otherwise do not score.

"Data size and conventions"
For 10% of data, n=1;
For 40% of data,n<=2;
For 60% of data,n<=100;
For 80% of data,n<=1000;
For all data, N <= 10000,0 <= Eu <= 108,0 < si <= 100000,0 < ki <= 1,-100 < VI ' < 100. Data guarantees that the final answer will not exceed 105.

Prompted
There must be an optimal physical solution: The eggs are used at a uniform speed on every part of the way.

Input

The first line contains a positive integer n and a real number EU, respectively, representing the quantity of the road segment and the physical fitness value of the egg. The next n lines describe n sections, each with 3 real si, ki, vi ', respectively representing the length of the section I, the wind resistance coefficient and the wind speed.

Output

Outputs a real number T, which indicates the shortest time the egg is consumed at the destination and requires at least 6 digits after the decimal point.

Sample Input
3 10000
10000 10 5
20000 15 8
50000 5 6

Sample Output12531.34496464
"Sample description" One possible scenario is that the balls are used at a constant speed of 5.12939919, 8.03515481, 6.17837967 in the three-segment way. If you do not understand the idea, it is recommended to see the MIT Lectures NetEase Open Class.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intmaxn=10010;6 DoubleS[MAXN],K[MAXN],V[MAXN];7 DoubleE,LAM,X[MAXN];8 intN;9 intMain () {Ten #ifndef Online_judge OneFreopen ("bicycling.in","R", stdin); AFreopen ("Bicycling.out","W", stdout); - #endif     -scanf"%D%LF",&n,&E); the      for(intI=1; i<=n;i++){ -scanf"%LF%LF%LF",&s[i],&k[i],&v[i]); -         if(s[i]==0.0) i-=1, n-=1; -     } +     Doublel=-1000.0, r=0.0, tot; -      for(intt=1; t<= -; t++){ +Lam= (L+R)/2.0; tot=0.0; A          for(intI=1; i<=n;i++){ at             DoubleLo=max (V[i],0.0), hi=1e20; -              for(intj=1; j<= -; j + +){ -                 Doublex= (Lo+hi)/2.0; -                 if(2*lam*k[i]*x*x* (X-v[i]) +1>0) -lo=X; -                 Else     inHi=X; -             } tox[i]=Lo; +tot+=s[i]*k[i]* (X[i]-v[i]) * (x[i]-v[i]); -         } the         if(tot>E) *R=Lam; $         ElsePanax NotoginsengL=Lam;  -     } the     Doubleans=0.0; +      for(intI=1; i<=n;i++) Aans+=s[i]/X[i]; theprintf"%.10lf\n", ans); +     return 0; -}

Advanced Mathematics (Lagrange multiplier method): NOI 2012 Riding Chuan Zang

Related Article

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.