Set value range + Interval overlay

Source: Internet
Author: User

Interval points + interval coverage

Interval selection problem (select the fewest points so that each interval has at least k points)

These intervals [l,r] are sorted according to r from small to large, and then by L from large to small.

Select the point near the right edge as far as possible. Then, according to this sort of interval to traverse, with a variable to hold the right boundary of the last interval of the traversal, and then encounter a new interval when there are two situations to discuss: 1, this interval and the previous interval has a part of the intersection, then you need to infer how many points of the last selection within this interval. Do these points meet the requirements? If you are not satisfied, you also need to have a point in this interval 2, this interval and the previous interval does not intersect, then this interval needs a point.

The above strategy can guarantee the same interval of the right boundary, first select the short interval.

Since the point of the short interval is selected, the larger interval of the same right boundary must include all points of the smaller interval selection. The likelihood of this larger interval being satisfied is greater.

And the strategy here is to take as close as possible to the right edge of the point, so that the selection of the number of satisfied intervals will be the largest.

Pseudo code
interval[maxn][2]; Sort (interval, interval + MAXN, CMP);//cmp According to R small L big priority high to arrangePre = interval[1][0] -1;//Create disjoint right boundary     forIn range (1, MAXN):ifinterval[i][0] > Pre://non-intersecting            //Near right border point        Else:///Find out how many points have been selected for this interval, and then select a point based on whether it meets the requirementsPre = interval[1][1];//Update right Border    Else:;

Title: Uva10148advertisement (range of selected points)

Interval coverage problem (select the minimum interval to make the overlay [m,n])

If the coverage interval is [M, N]. First dispose of the interval that is not in the [M,n]. Put the beginning of the small area in front, if the beginning of the same interval to put the long interval in front.

Do two special sentences, infer whether the first interval of the beginning covers m, and whether the final overlay has coverage to N.

Then there is the middle inference, the middle inference look at the code bar.

Pseudo code
interval[maxn][2]; VIS[MAXN];//record which side is selected    //delete and [M, N] not in the range, and according to L small R big priority high orderfunction Cover_interval:ifinterval[0][0] < M//Whether to cover M            return false; Pre = m;The right boundary of the previous selection interval and the valid starting boundary for the next selection intervalt =-1;//Record the subscript of the previous interval, since it may not be the best intervalCover = M-1;//The location is now covered         forIn range (1, MAXN):ifinterval[i][0] <= Pre://Meet at least cover to the right boundary of the previous interval pre, so that the entire coverage of the interval will not be broken                ifinterval[i][1] > cover://Select the longest range to meet the above requirementsVis[i] =1; Cover = interval[i][1];//Update coverage location                    ifT! =-1://Last selected CancelVIS[T] =0;Else://Do not meet the requirements to indicate the need to select the next new interval, update the prePre = cover;ifinterval[i][0] > Pre://Assuming that the left edge of the current interval is larger than the coverage position, then there is a section in the middle that is not covered                    return false; t =-1;//new interval empty last selectedi--;ifCover >= N: Break;Else:;ifCover < nreturn false;//Output selected range according to VIS[MAXN]        return true; function end;

Title: Uva10020-minimal Coverage (interval coverage) uva10382-watering Grass (deformation interval overlay)

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Set value range + Interval overlay

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.