HDU 今年暑假不AC

典型的活动安排问题,先将活动按照结束时间进行排序。。。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace
std;
int
N;
struct
show
{

    int
start;
    int
end;
};

show shows[110];
int
cmp(const void* a,const void* b)
{

    show c=*(show*)a;
    show d=*(show*)b;
    if
(c.end==d.end)
    {

        return
c.start-d.start;
    }

    else
    return
c.end-d.end;
}

int
main()
{

    int
i;
    while
(scanf("%d",&N)!=EOF)
    {

        if
(N==0)break;
        int
number=0;
        for
(i=0;i<N;i++)
        {

            scanf("%d %d",&shows[i].start,&shows[i].end);
        }

        qsort(shows,N,sizeof(shows[0]),cmp);
        int
temp=0;
        for
(i=0;i<N;i++)
        {

            if
(shows[i].start>=temp)
            {

                number++;
                temp=shows[i].end;
            }
        }

        printf("%d\n",number);
    }

    return
0;
}

posted on 2011-07-18 16:44  lonelycatcher  阅读(181)  评论(0编辑  收藏  举报

导航