Lecture Halls

Lecture Halls (会议安排) 分享至QQ空间 去爱问答提问或回答

时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
总提交: 38            测试通过: 20

描述

 

假设要在足够多的会场里安排一批活动,并希望使用尽可能少的会场。设计一个有效的算法进行安排。(这个问题实际上是著名的图着色问题。若将每一个活动作为图的一个顶点,不相容活动间用边相连。使相邻顶点着有不同颜色的最小着色数,相应于要找的最小会场数。)

编程任务: 对于给定的k个待安排的活动,编程计算使用最少会场的时间表。

 

输入

输入数据是由多组测试数据组成。每组测试数据输入的第一行有1 个正整数k,表示有k个待安排的活动。接下来的k行中,每行有2个正整数,分别表示k个待安排的活动开始时间和结束时间。时间以0 点开始的分钟计。

输出

对应每组输入,输出的每行是计算出的最少会场数。

样例输入

 

5
1 23
12 28
25 35
27 80
36 50

 

样例输出

 

3

 

题目上传者

crq

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 1000000;
int n;
int v[maxn];


int main()
{
    int from, to, i, res;
    while(scanf("%d", &n) != EOF) {
        memset(v, 0, sizeof(v));
        for(i = 0; i < n; i++) {
            scanf("%d%d", &from, &to);
            v[from] += 1;
            v[to] += -1;
        }
        res = 0;
        int maxv = -INF;
        for(i = 0; i < maxn; i++) {
            res += v[i];
            if(res > maxv) {
                maxv = res;
            }
        }
        cout << maxv << endl;
    }
    return 0;
}


原文地址:https://www.cnblogs.com/pangblog/p/3262967.html