9度OJ 1463 贪心算法、优先队列、运算符重载之《招聘会》
九度OJ 1463 贪心算法、优先队列、运算符重载之《招聘会》
题目地址:http://ac.jobdu.com/problem.php?pid=1463
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #define MAXS 1002 using namespace std; typedef struct E{ int s; int e; bool operator > (E A) const { return e>A.e; } bool operator < (E A) const { return e<A.e; } }E; priority_queue<E,vector < E >,greater < E > >Q; int main() { E time; int sum,n,i,j; while(~scanf("%d",&n)) { if(n==0){printf("0\n");continue;} while(Q.empty()==false)Q.pop(); while(n--) { scanf("%d %d",&time.s,&time.e); Q.push(time); } sum=1;time=Q.top();Q.pop();j=time.e; while(Q.empty()==false) { time=Q.top(); Q.pop(); if(time.s>=j) { j=time.e; sum++; } } printf("%d\n",sum); } return 0; }