51nod 1428 Event scheduling problem (priority queue)

Source: Internet
Author: User

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)

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.