方法:
优先队列,以结束时间早的为先。
AC代码:
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
struct jiemu
{
int begg;
int endd;
bool operator < (const jiemu &p)const
{
return endd>p.endd;
}
};
int main()
{
int n;
while(cin>>n&&n)
{
priority_queue<jiemu> s;
while(n--)
{
int x,y;
cin>>x>>y;
jiemu news;
news.begg = x;
news.endd = y;
s.push(news);
}
int now = 0;
int ans = 0;
while(!s.empty())
{
jiemu news = s.top();
if(news.begg>=now)
{
ans++;
now = news.endd;
}
s.pop();
}
cout<<ans<<endl;
}
return 0;
}

736

被折叠的 条评论
为什么被折叠?



