题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037
贪心水题。。。
//贪心 选择不相交区间
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct nood
{
int s,e;
}t[101];//结构体 存区间
bool camp(nood o1,nood o2)
{
if(o1.e<o2.e) return true;
else return false;
}
int main()
{
freopen("in.txt","r",stdin);
int n,a,sign;
while(scanf("%d",&n),n)
{
sign=1;
for(int i=0;i<n;i++)
scanf("%d%d",&t[i].s,&t[i].e);
sort(t,t+n,camp);//用快排 对每个区间的结束进行排序
a=t[0].s;
for(int i=1;i<n;i++)//排序以后,对每个区间开始进行计较,
{
if(a<=t[i].s)
{
sign++;// 找到一个进行标记
a=t[i].e;
}
}
printf("%d\n",sign);
}
return 0;
}