zoukankan      html  css  js  c++  java
  • 会场问题 差分解法

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

    /**/
    #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:
    */
    
  • 相关阅读:
    Find a way(两个BFS)
    ACM代码模板
    ElasticSearch-集群
    ElasticSearch-倒排索引
    ElasticSearch-IK分词器
    ElasticSearch-数据类型
    ElasticSearch-REST APIS
    cmd命令行中的errorlevel和延迟赋值
    ubuntu 12.04内核升级到3.13.1
    ubuntu 12.04安装TP-LINK TL-WN725N v2
  • 原文地址:https://www.cnblogs.com/000what/p/11656869.html
Copyright © 2011-2022 走看看