Interval selection + interval coverage
Interval point selection problem (select the least point so that each interval has at least K points)
Sort these intervals [L, R] in ascending order of R and then in descending order of L. Select a point close to the right border as much as possible. Then, we traverse the sorted intervals and use a variable to store the right boundary of the upper interval in the traversal process. When we encounter a new interval, we need to discuss it in two cases: 1. If this interval has an intersection with the previous interval, You need to determine the number of points selected last time in this interval. Do these points meet the requirements? If this parameter is not met, You need to select vertex 2 in this interval. If this interval does not have an intersection with the previous one, you need to select a vertex in this interval.
The preceding policy ensures that the right boundary is the same. Select the shorter boundary. Because the vertex in the short interval is selected, a larger interval with the same right boundary must include all the vertices selected in this smaller interval, in this way, the range of this big point is more likely to be satisfied. In addition, the method for selecting a vertex here is to take the vertex as close as possible to the right border, so that the number of satisfied intervals is the largest.
Pseudocode
Interval [maxn] [2]; sort (interval, interval + maxn, CMP ); // CMP arranges pre = interval [1] [0]-1 according to the R small l high priority; // creates an exclusive right boundary for in range (1, maxn): If interval [I] [0]> pre: // not intersecting // near the right boundary else: // first, find the selected number of points in this interval, then select pre = interval [1] [1] according to whether the requirements are met; // update the right boundary else :;
Question: uva10148advertisement (interval selection)
Range coverage (select the least range to overwrite [M, N])
Assume that the covered range is [M, N]. First, the range of [M, N] and [M, N] are pre-processed. Place the interval with a small starting point in front. If the starting point is the same, place the long interval in front. Make two special judgments to determine whether the first range of the start point covers M and whether the last coverage covers n. The next step is the intermediate judgment. The intermediate judgment depends on the code.
Pseudocode
Interval [maxn] [2]; vis [maxn]; // records the range of edges selected/deleted and [M, N] not touched, function cover_interval: If interval [0] [0] <m // whether to cover M return false; Pre = m; // The right boundary of the previous selection interval, which is also the valid starting boundary t =-1 for the next selection interval; // record the subscript of the previous range, probably this interval is not the best interval cover = m-1; // the position already overwritten for in range (1, maxn ): if interval [I] [0] <= pre: // satisfies the condition that at least the upper boundary pre is overwritten, so that the entire covered range will not be disconnected if interval [I] [1]> cover: // select the longest range that meets the preceding requirements vis [I] = 1; cover = interva L [I] [1]; // update the overwrite location if T! =-1: // The last selected cancelling vis [T] = 0; else: // If the else does not meet the requirements, you need to select the next interval and Update pre = cover; if interval [I] [0]> pre: // If the left boundary of the current range is greater than the overwrite position, return false is not covered in the middle; T =-1; // The new interval clears the previously selected I --; If cover> = N: break; else:; If cover <n return false; // output the selected range according to vis [maxn] Return true; function end;
Question: uva10020-minimal coverage (range coverage) uva10382-watering grass (range coverage deformation)
Interval selection + interval coverage