0.75
Analysis:
To obtain the maximum unit weight value, you need to perform a binary search between 0 and Max. Max is the maximum unit weight value obtained from any selected item,
Max = max (V [I]/W [I] | I = 0... n-1 ).
Why is Max so valid? The following example shows:
Assume that a pair of VI and WI meet the following requirements: VI/Wi = max (V [I]/W [I] | I = 0 ...... n-1), any pair of VK, wk (K! = I), there are vi/wi> VK/wk,
That is, VI * wk> VK * WI records it as Formula 1.
Proof:
What you want to prove is (vi + VK1 +... + vk2)/(WI + wk1 +... + WK2) <= VI/WI, (0 <= k1 <= k2 <= n-1 & K1! = I & K2! = I ),
1. When k1 = k2 = 0, that is, no value is added. The upper equals sign is valid.
2. For ease of proof, only VK (K! = I), it is common. Certificate (vi + VK)/(WI + WK) <VI/WI,
That is, WI (vi + VK) <VI (WI + WK), that is, VI * wk> VK * WI. This formula is Formula 1!
3. When the number of 2... N-1 is increased, it is also true.
4. Pass the certificate.
For more information about cleck (A), see the code below.
# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 10000 + 5; Double X [maxn], W [maxn], V [maxn]; // fully defined as double, which facilitates the calculation of int N, K; bool cleck (double A) {for (INT I = 0; I <n; I ++) x [I] = V [I]-A * W [I]; sort (x, x + n); double sum = 0; for (INT I = 0; I <K; I ++) sum + = x [n-I-1]; // greedy, return sum> = 0? True: false;} int main () {While (~ Scanf ("% d", & N, & K) {double max = 0; For (INT I = 0; I <n; I ++) {scanf ("% lf", & W [I], & V [I]); max = max (max, V [I]/W [I]);} double L = 0, r = max; while (R-l> 1e-4) {// binary search optimal value double M = (L + r)/2; If (cleck (M) L = m; else r = m;} printf ("%. 2lf \ n ", L);} return 0 ;}
Cleck (a) checks whether the unit weight value a is desirable. If yes, it must meet
(VK1 +... + vk2)/(wk1 +... + WK2)> = a (0 <= k1 <= k2 <= N-1 ),
That is, VK1 +... + vk2> = a (wk1 +... + WK2 ),
VK1-A * wk1 +... + vk2-A * WK2> = 0
Therefore, we recommend that you use vki-A * wki (that is, XI in the Code) as much as possible.