原题链接:HDU—2037
题目大意:中文题目。
题目解法:老题了,用各个节目的结束实践给各个数据排序,然后从第一个节目开始判断后一个节目的开始时间是否大于前一个可看节目结束时间,如果小于那么可看的节目加一,并更新目前最后一个可看节目的结束时间,否则继续判断下一个,其实很简单,不理解的可以自己代代数据做做试验就可以验证了。
题目代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node
{
int a,b;
};
int cmp(struct node c,struct node d)
{
return c.b<d.b;
}
struct node table[200];
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
int i;
for(i=0;i<n;i++)
scanf("%d%d",&table[i].a,&table[i].b);
sort(table,table+n,cmp);
int last=table[0].b;
int number=1;
for(i=1;i<n;i++)
{
if(table[i].a>=last)
{
last=table[i].b;
number++;
}
}
printf("%d\n",number);
}
return 0;
}
欢迎留言哦!