题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037
题意:中文题
解析:贪心水题,按右区间排序从小到大排序,每次拿出一个和前一个的右区间进行比较,合法ans++,并且更新记录
#include <bits/stdc++.h>
using namespace std;
struct node
{
int l,r;
bool operator < (const node b)const
{
return r<b.r;
}
}a[104];
int main(void)
{
int n;
while(~scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++)
scanf("%d %d",&a[i].l,&a[i].r);
sort(a,a+n);
int ans = 1;
int last = a[0].r;
for(int i=1;i<n;i++)
{
if(a[i].l>=last)
{
ans++;
last = a[i].r;
}
}
printf("%d\n",ans);
}
return 0;
}