Topic link CCPC Harbin problem K
Test instructions given a number of items, each item can cover an interval. Now to cover the interval $[1, t]$.
The minimum value of the $\frac{∑a_{i}}{∑b_{i}}$ of the selected item.
First two answers, then the weight of each item becomes $x * B_{i}-a_{i}$
At the time of judgment, all the items of the right value are chosen first.
Then record the location of the right-most endpoint that can be overwritten from the beginning of the $1$.
Next start DP, sort by the endpoint of the interval ascending (left endpoint first keyword, right endpoint second keyword)
The question is whether you can use the remaining items to cover areas that have not yet been covered.
Then the direct use of a tree-like array to optimize DP.
#include <bits/stdc++.h>using namespace std; #definerep (i, A, b) for (int i (a); I <= (b); ++i) #definedec (i, A, b) fo R (int i (a); I >= (b); i) #definefifirst #definesesecondconst int N = 1e5 + 10;struct node{int s, t;double A, B;bool FL Ag;void Scan () {scanf ("%d%d%lf%lf", &s, &t, &a, &b);} friend BOOL operator < (const node &a, const node &b) {return A.S = = B.S? a.t < B.t:a.s < B.S;}} A[n];int t;int N, m;double c[n];d ouble L, r;void Update (int x, double val) {for (; x; x = x & x) c[x] = min (C[x], Val );} Double query (int x) {if (x = = 0) return 0;double ret = 1e9;for (; x <= m; x + = x & x) ret = min (ret, c[x]); return r ET;} BOOL Check (double x) {int mx = 0;double ss = 0;rep (i, 0, m) c[i] = 1e9;rep (i, 1, n) {if (a[i].b * x-a[i].a > 0) {ss + = A [i].b * X-a[i].a;a[i].flag = true;if (a[i].s-1 <= mx) {mx = max (mx, a[i].t);}} else A[i].flag = false;} if (mx = = m) return true;update (MX, 0); Rep (i, 1, n) {if (!a[i].flag) {Double mi = query (a[i].S-1); Update (A[I].T, MI + a[i].a-a[i].b * x);} else{double mi = query (a[i].s-1); Update (a[i].t, MI);}} return SS >= query (m);} int main () {scanf ("%d", &t), while (t--) {scanf ("%d%d", &n, &m), Rep (i, 1, N) a[i].scan (); sort (A + 1, a + n + 1); l = 0, R = 1e3 + 10;rep (i, 1,) {Double mid = (L + R)/2.00;if (check (mid)) R = Mid;else L = mid;} printf ("%.3f\n", L);} return 0;}
HDU 6240 Server ccpc Harbin Station K, 01 score plan + Tree array optimization dp)