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;
    }
    梦里不知身是客,一晌贪欢。
  • 相关阅读:
    Xib和storyboard对比
    IOS中用模型取代字典的好处
    IOS中UIButton和UIImageView的区别
    Response对象
    ASP.NET内置对象
    ASP.NET最常用的页面生命周期事件
    构造函数与析构函数
    C#程序设计基础——类、对象、方法
    CI框架分页(不解错误)
    Linux 下直连ipad mini充电(实战)
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/4686369.html
Copyright © 2011-2022 走看看