首页 > 代码库 > HihoCoder 1309

HihoCoder 1309

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=1e6+100;
priority_queue<int,vector<int>,greater<int> >q;//从大到小的优先队列
pair<int,int>x[maxn];

int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x[i].first,&x[i].second);
}
sort(x,x+n+1);//先按开始时间排序,开始相等按结束排序
q.push(0);
for(int i=1;i<=n;i++)
{
if(q.top()<=x[i].first)
{
q.pop();
q.push(x[i].second);
}
else
q.push(x[i].second);
}
cout<<q.size()<<endl;
}
}

HihoCoder 1309