1428 Event Scheduling issues
Start by starting from small to large sort first.
In fact, as long as the minimum heap to maintain an end time, each time compared to the start time and the minimum time in the heap size, if larger than it is placed in the heap and the time will become the current task end time,
Otherwise, we will open a new classroom. and add the end time to the heap, and be careful to determine if the heap is empty.
#include <cstdio>#include<cstring>#include<queue>#include<algorithm>using namespacestd;structpoint{intx, y; BOOL operator< (ConstPoint a)Const { returnx<a.x; }}p[10001];intMain () {intN; Priority_queue<int,vector<int>,greater<int> >que; scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d%d",&p[i].x,&p[i].y); Sort (p,p+N); //for (int i=0;i<n;i++) printf ("%d%d\n", p[i].x,p[i].y);Que.push (p[0].y); intans=1; for(intI=1; i<n;i++) { if(!Que.empty ()) { intA=Que.top (); //printf ("%d\n", p[i].x); if(p[i].x>=a) {Que.pop (); A=p[i].y; Que.push (a); } Else{ans++; Que.push (P[I].Y); } } Else{ans++; Que.push (P[I].Y); }} printf ("%d\n", ans); return 0;}
View Code
51nod 1428 Event scheduling problem (priority queue)