思路:按照结束时间排序一下,然后贪心第一个必选,随便做做就可以了
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 100+100
#define LL long long
int cas=1,T;
int n;
struct TV
{
int s;
int e;
}tv[maxn];
bool cmp(TV a,TV b)
{
if (a.e==b.e)
return a.s<b.s;
return a.e<b.e;
}
int main()
{
//freopen("in","r",stdin);
//scanf("%d",&T);
while (scanf("%d",&n)!=EOF&&n)
{
for (int i = 0;i<n;i++)
scanf("%d%d",&tv[i].s,&tv[i].e);
sort(tv,tv+n,cmp);
int ans = 1;
int start = tv[0].e;
for (int i = 1;i<=n-1;i++)
{
if (tv[i].s>=start)
{
ans++;
start=tv[i].e;
}
}
printf("%d\n",ans);
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}