POJ-2976 dropping tests
You have \ (n\) exam results, the definition of the Test average score of \[\frac{\sum_{i = 1}^{n} a_{i}}{\sum_{i = 1}^{n} b_{i}}\]
You may consider giving up \ (k\) grades, asking for the maximum average score * 100
Episode: Being precision Kacheng sheep and sheep
0/1 Fractional Planning\ (from\)Life Mentor Solution
01 Score Planning (not very) bare topic, in each \ (check\) , select the larger \ (num-k + 1\) times to
Code
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include < algorithm> #include <climits> #define LL long longusing namespace std;double RD () {double out = 0,flag = 1;char C = GetChar (); while (C < ' 0 ' | | c > ' 9 ') {if (c = = '-') ' flag = -1;c = GetChar ();} while (c >= ' 0 ' && C <= ' 9 ') {off = out * + C-' 0 '; c = GetChar ();} return flag * out; }const int maxn = 2019;int num, k;double A[MAXN], B[maxn],c[maxn];bool check (double K) {for (int i = 1;i <= num;i++) { C[i] = A[i]-b[i] * k; } sort (c + 1, C + 1 + num); Double temp = 0; for (int i = num;i > k;i--) Temp + = C[i]; if (Temp > 0) return 1; return 0; }double Search (double L, double R) {double ans; while (R-l > 0.000000001) {Double mid = (L + r)/2; if (check (mid)) ans = Mid, L = mid; else R = Mid; } return ans; }int Main () {while (1) {num = rd (), K = Rd (); if (!num&&! K) return 0; for (int i = 1;i <= num;i++) a[i] = RD (); for (int i = 1;i <= num;i++) b[i] = RD (); printf ("%.0f\n", * search (0, 1000000019)); } }
POJ-2976 dropping tests && 0/1 score plan