• 会场问题 差分解法


    之前写会场问题都是用贪心,很麻烦。(给出开始结束时间,求最少需要房间数)
    差分写法如下:

    /**/
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cctype>
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <set>
    #include <vector>
    #include <string>
    #include <stack>
    #include <queue>
    
    typedef long long LL;
    typedef unsigned long long ULL;
    using namespace std;
    
    bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
    const double PI = acos(-1.0), ESP = 1e-10;
    const LL INF = 99999999999999;
    const int inf = 999999999, N = 2e6 + 24;
    int n, a, b, u, h[N];
    
    int main()
    {
    	//freopen("in.txt", "r", stdin);
    	//freopen("out.txt", "w", stdout);
    	scanf("%d", &n);
    	for(int i = 1; i <= n; i++) {
    		scanf("%d%d", &a, &b);
    		h[a]++; h[b+1]--;
    		if(b > u) u = b;
    	}
    	a = h[0];
    	for(int i = 1; i <= u; i++) {
    		h[i] += h[i-1];
    		if(h[i] > a) a = h[i];
    	}
    	printf("%d
    ", a);
    
    
    	return 0;
    }
    /*
        input:
        output:
        modeling:
        methods:
        complexity:
        summary:
    */
    /*
        input:
        output:
        modeling:
        methods:
        complexity:
        summary:
    */
    
  • 相关阅读:
    搜狗输入法ubuntu
    数学
    1
    狗蚂蚁, 模拟题.
    最小公倍数
    哈夫曼费用计算C++
    C++十进制到任意进制
    【Django QuerySet API009】
    【Django模型(数据库)008】
    【Django模板进阶007】
  • 原文地址:https://www.cnblogs.com/000what/p/11656869.html
Copyright © 2020-2023  润新知