贪心FB

hdu 2037  今年暑假不AC

思路: 定义结构体,排序,然后贪心。

(如需输出最多可看的节目是哪些,可以使用标记数组来记录)

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct T{
    int s,e;
};
T program[105];
bool  cmp(const T a,const T b)
{
    if(a.e != b.e)
        return a.e < b.e;
}

bool Selected[105];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF && n)
    {
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d",&program[i].s,&program[i].e);
        }
        sort(program,program+n,cmp);
int j = 0, cnt = 1;
for(int i = 1; i < n; i++) { if(program[i].s >= program[j].e) { cnt++; j = i; } } printf("%d\n",cnt); memset(program,0,sizeof(program)); } return 0; }

 

posted @ 2015-08-08 17:56  PosProteus  阅读(160)  评论(0编辑  收藏  举报