zoukankan      html  css  js  c++  java
  • 区间的最大重叠度(会议安排问题)

    其实就是区间最多重叠数目。

     

    定义一个op作为区间重叠度,从头扫描到尾部,若op进入一个区间的开始端,说明op在此区间内部,继续扫描若在遇到一个区间的开始端op就再加一,若op遇到一个区间的末端,说明op已经走出某个区间,就让op减一,就这样让op一直走到结束,记录下op的曾经的最大值,就是区间重叠最多的和数目
    #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;
    }
    梦里不知身是客,一晌贪欢。
  • 相关阅读:
    Noip2012 开车旅行
    「NOI2018」归程
    2019.10.30 队测(晚上)
    洛谷P1138 第k小整数
    洛谷P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold
    Noip-pj2018游记
    洛谷P4994 终于结束的起点
    《退役的你》
    《膜你抄》
    洛谷P5087 数学
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/4686369.html
Copyright © 2011-2022 走看看