IT民工
加油!

  贪心,以时间点i开始的活动数目为beg[i],结束的记为end[i], 然后每扫到一个开始和结

束,数组都计数。然后统计一天同一个时间点有多少个开始就行了,遇到结束要减去。最小

的天数就求出来了。

 

/*Accepted    3650    15MS    916K    881 B    C++    Yu*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

const int MAXN = 24 * 3600;
int beg[MAXN + 10], end[MAXN + 10];
int n, yMax, x, y, ans, cnt;

int main()
{
    int i;
    while(scanf("%d", &n), n)
    {
        memset(beg, 0, sizeof beg);
        memset(end, 0, sizeof end);
        ans = cnt = yMax = 0;
        for(i = 0; i < n; i ++)
        {
            scanf("%d%d", &x, &y);
            beg[x] ++; //这个时间开始的活动
            end[y] --; //这个时间结束的活动
            yMax = max(y, yMax);
        }
        for(i = 0; i <= yMax; i ++)
        {
            if(beg[i] > 0)
            {
                cnt += beg[i];
                ans = max(ans, cnt);
            }
            if(end[i] < 0)
            {
                cnt += end[i];
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

 

 

posted on 2012-09-17 15:28  找回失去的  阅读(233)  评论(0)    收藏  举报