Output
Sample Input
Sample Output
该题题意为有很多电视节目,时间段不同,能看的电视节目最多有几个;
#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct x
{
int a;
int b;
} c[100];
int cmp(struct x e,struct x f)
{
if(e.b!=f.b)
return e.b<f.b;
}
int main()
{
int n,i,ge,x,y,j,t,s;
for(;;)
{
scanf("%d",&n);
if(n==0)
break;
for(i=0; i<=n-1; i++)
scanf("%d%d",&c[i].a,&c[i].b);
sort(c,c+n,cmp);
x=0;
ge=1;
t=0;
for(;;)
{
i=x;
s=c[i].b;
if(s>c[n-1].a)
break;
for(j=0; j<=n-1; j++)
if(j>i&&c[j].a>=s)
{
x=j;
ge++;
break;
}
}
printf("%d\n",ge);
}
}
本文介绍了一种通过算法确定在不重叠的时间段内能够观看的最大数量电视节目的方法。输入包括多个测试实例,每个实例包含一系列节目的开始和结束时间,目标是最大化可完整观看的节目数量。
193

被折叠的 条评论
为什么被折叠?



