The number of meetings attended leetcode 1353. Up (+ greedy priority queue)

Subject description:

 

 Solution: First start date in ascending order of the meeting. After day by day to traverse , the conference start date to end date day meeting in the priority queue (small root heap), a daily schedule from a priority queue to be able to participate in the conference.

Note two points, the start date in ascending order of the meeting is to be able to participate in the meeting as early as possible. The deadline in the priority queue conference is to be able to arrange the most urgent task of the day, this is a greedy.

(Week tournament play, when life and death did not expect to deal with priority queues, less experience)

 

AC Code:

int maxEvents(vector<vector<int>>& events) {
        int Len = events.size();
        sort(events.begin(),events.end());
        priority_queue<int,vector<int>,greater<int>> q;
        int ans = 0;
        int line = 1;
        int i = 0;
        while(i<Len || q.size() != 0)
        {
           while(i<Len && events[i][0] == line)
           {
               q.push(events[i][1]);
               i++;
           } 
           // has been unable to participate in 
           the while (! Q.size () = 0 && q.top () < Line) q.pop ();
            IF (! Q.size () = 0 )
           {
               years ++ ;
               q.pop();
           }
           line++;
        }
        return ans;
    }

 

Guess you like

Origin www.cnblogs.com/z1141000271/p/12325196.html