51Nod 1428 Event Scheduling issues
link:http://www.51nod.com/onlinejudge/questioncode.html#!problemid=1428
1428 scheduling issues Base time limit: 1 seconds space limit: 131072 KB Score: 10 Difficulty: 2 level algorithm problem has a number of activities, the first start and end time is [Si,fi], the same classroom arrangement of activities can not overlap, to arrange all activities, the minimum number of classrooms required? Input
The first line, a positive integer n (n <= 10000), represents the number of activities. The second line to the (n + 1) row contains n start time and end time. The start time is strictly less than the end time, and the time is a non-negative integer, less than 1000000000
Output
A row contains an integer that represents the minimum number of classrooms.
Input example
31 23 42 9
Output example
2
Exercises
Simple topics, after sorting, put into the priority queue, to simulate, solve!
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int MAXN = 100000 + 5; struct node{int R, l;} ND[MAXN]; int n; int cmp (const void *a, const void *b) {node *AA = (node *) A; Node *BB = (node *) b; Return aa->l-bb->l; }int Main () {///freopen ("In.txt", "R", stdin); int x, y, p, ans, cur; while (scanf ("%d", &n)! = EOF) {for (int i=0; i<n ; ++i) {scanf ("%d%d", &ND[I].L, &ND[I].R);} Qsort (ND, N, sizeof (nd[0]), CMP); ans = 1; Priority_queue<int, Vector<int>, greater<int>> qt; Qt.push (ND[0].R); for (int i=1; i<n; ++i) {if (!qt.empty ()) {cur = qt.top (); if (nd[i].l >= cur) {qt.pop (); } Else{++ans;} Qt.push (ND[I].R); }else{qt.push (ND[I].R);}} printf ("%d\n", ans);} return 0; }
51Nod 1428 Event Scheduling issues