AcWing 906. Packet Interval

// 1. All the left end sections in ascending order
 // 2 from front to back for each processing interval, determines whether to place an existing group
 // Analyzing the last interval of a group the left end of the right end is smaller than the interval
 // if more than or equal, to open a new group, is less than, to go into the group, and the right end point of the last update interval 
#include <the iostream> 
#include <algorithm> 
#include <Queue>
 the using  namespace STD;
 const  int N = 100010 ;
 int n-;
 struct the Range {
     int L, R & lt;
     BOOL  operator <( const the Range W is &) const {
         return L < Wl of the; 
    } 
} Range [N];
int main () { 
    Scanf ( " % D " , & n-);
     for ( int I = 0 ; I <n-; I ++ ) {
         int L, R & lt; 
        Scanf ( " % D% D " , & L, & R & lt ); 
        Range [I] = {L, R & lt}; 
    } 
    Sort (Range, Range + n-); 
    the priority_queue < int , Vector < int >, Greater < int >> heap; // maintain maximum right end points of all groups 
    for ( int I = 0; i < n; i ++ ) {
        auto r = range[i];
        if (heap.empty() || heap.top() >= r.l)
            heap.push(r.r);
        else {
            heap.pop();
            heap.push(r.r);
        }
    }
    printf("%d\n", heap.size());
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11909463.html