题目链接:http://codeforces.com/contest/597/problem/B
题目分类:贪心
题目分析:经典的看节目问题(挑战程序设计page 40)
代码:
#include<bits/stdc++.h> using namespace std; struct P
{
int st,en;
}order[]; int cmp(P X,P Y)
{
return X.en<Y.en;
} int main()
{
int n;
scanf("%d",&n);
memset(order,,sizeof(order));
for(int i=;i<=n;i++)
{
cin>>order[i].st>>order[i].en;
} sort(order+,order+n+,cmp); int ans=,t=;
for(int i=;i<=n;i++)
{
if(order[i].st>t)
{
ans++;
t=order[i].en;
} }
printf("%d\n",ans);
return ;
}