输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0
lcy | We have carefully selected several similar problems for you:
1050
1009
1051
1052
1789
|
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Show{
int start,end;
};
Show show[110];
bool cmp(Show a,Show b)
{
return a.end<b.end;
}
int main()
{
int n,i;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
scanf("%d%d",&show[i].start,&show[i].end);
sort(show,show+n,cmp);
int s=1;
int m=show[0].end;
for(i=1;i<n;i++)
{
if(show[i].start>=m)
{
s++;
m=show[i].end;
}
}
printf("%d\n",s);
}
return 0;
}
|