輸入數據包含多個測試實例,每個測試實例的第一行只有一個整數n(n<=100),表示你喜歡看的節目的總數,然后是n行數據,每行包括兩個數據Ti_s,Ti_e (1<=i<=n),分別表示第i個節目的開始和結束時間,為了簡化問題,每個時間都用一個正整數表示。n=0表示輸入結束,不做處理。
Output
對于每個測試實例,輸出能完整看到的電視節目的個數,每個測試實例的輸出占一行。
Sample Input
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
Sample Output
5
#include<stdio.h>
int main()
{
int n1;
int i,j,temp;
scanf("%d",&n1);
struct N{
int s;
int f;
}n[102],t;
while(n1!=0)
{
for(i=1;i<=n1;i++)
{
scanf("%d",&n[i].s);
scanf("%d",&n[i].f);
}
for(i=1;i<=n1;i++)
{
for(j=n1;j>i;j--)
{
if(n[i].s>n[j].s)
{
t=n[i];
n[i]=n[j];
n[j]=t;
if(n[i].f>n[i].f)
{
temp=n[i].f;
n[i].f=n[j].f;
n[j].f=temp;
}
}
}
}
// for(i=1;i<=n1;i++)
// printf("%d %d\n",n[i].s,n[i].f);
int c=1,k=n1,j=0;
int s=0;
while(k)
{
j=k;c=1;
for(i=n1-1;i>=1;i--)//只能從下到上;
{
if(n[i].f<=n[j].s)
{ j=i;
c++;
}
}
if(s<c)
s=c;
k--;
}
printf("%d\n",s);
scanf("%d",&n1);
}
return 0;
}