Title: There is a race divided into two parts of running and cycling, the total length must (L), the last contestant bribed the referee,
The referee adjusts the proportions of the two parts, and he wants to ask for the maximum value of the second place.
Analysis: The maximum value of the single-peak function is obtained by three points. Set the first part length is x, the length of the second part is l-x,t (x) = x/v + (l-x)/u;
f (x) = max (X/vn + (l-x)/un-(X/VI + (l-x)/UI));
= X/vn + (l-x)/un-min (X/vi + (l-x)/UI);
The following proves that F (x) is a single-peak function (that is, min (X/vi + (l-x)/UI) is a single-peak function):
First, it consists of only two straight lines, which must be a single-peak function (or monotonous);
Again, set I line is a single-peak, insert section i+1 (Yellow Line), then get a new function;
wherein, the line slope on the left intersection must be less than li+1, and the straight slope of the right intersection must be greater than li+1;
(Because the slope on the right after the intersection is large on top, the left slope is small on top)
The continuous piecewise function consisting of straight line segments with increasing slope is a single peak (the lowest ends are monotonous);
conclusion, the single peak function of f (x) is fully integrated.
Description: ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;const int data_size = 10001;double L,u[data_size],v[data_size]; Double F (int n, double x, double L) {double min_value = x/u[1] + (l-x)/v[1];for (int i = 2; i < n; + + i) Min_value = min (Min_value, X/u[i] + (l-x)/v[i]); return Min_value-x/u[n]-(l-x)/v[n];} int main () {int n;while (~scanf ("%lf%d", &l,&n)) {for (int i = 1; I <= n; + + i) scanf ("%lf%lf", &u[i],&v[i] );d ouble L = 0,r = L,div_l,div_r;while (R-l > 1e-4) {div_l = L + (r-l)/3.0;div_r = R-(r-l)/3.0;if (F (n, div_l, L) ; F (n, Div_r, L)) R = Div_r;else L = div_l;} if (f (N, L, L) < 0) printf ("The Cheater cannot win.\n"); else {printf ("The Cheater can win by%.0LF", F (N, L, L) *3600);p RI NTF ("seconds with r =%.2lfkm and k =%.2lfkm.\n", l,l-l);}} return 0;}
UVa 10385-duathlon