c++ priority_queue和sort自定义

/**
 * Definition for an interval.
 * struct Interval {
 *     int start;
 *     int end;
 *     Interval() : start(0), end(0) {}
 *     Interval(int s, int e) : start(s), end(e) {}
 * };
 */
struct pqCmp{
        bool operator()(Interval a,Interval b){
            return a.end>b.end;
        }
};
bool cmp(Interval a,Interval b){
        return a.start& intervals) {
        priority_queue, pqCmp > room;
        //sort intervals by start time
        sort(intervals.begin(),intervals.end(),cmp);
        for(auto it:intervals){
            if(room.empty()){room.push(it); continue;}
            Interval curmin=room.top();
            if(it.start>=curmin.end){
                room.pop();
                curmin.end=it.end;
                room.push(curmin);
            }
            else room.push(it);
        }
        return room.size();
    }
};

 

你可能感兴趣的:(algorithm)