51Nod 1428 Event Scheduling issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.