zoukankan      html  css  js  c++  java
  • [洛谷P2161][SHOI2009]会场预约

    题目大意:有两种操作:

    1. $A;l;r:$表示加入区间$[l,r]$,并把与之冲突的区间删除,输出删除的区间的个数,区间$A$于区间$B$冲突当且仅当$Acap B ot=varnothing$
    2. $B:$输出现在有几个区间

    题解:用$STL$的$set$,定义区间$A<B$为$A.r<B.l$,这样寻找冲突的区间只需要在$set$中$find$即可,注意删除后$set$指针不可用,需要重新找

    卡点:

    C++ Code:

    #include <cstdio>
    #include <set>
    int n;
    struct Interval {
    	int l, r;
    	inline Interval() {}
    	inline Interval(int __l, int __r) : l(__l), r(__r) {}
    	inline friend bool operator < (const Interval &lhs, const Interval &rhs) {
    		return lhs.r < rhs.l;
    	}
    } ;
    std::set<Interval> S;
    int main() {
    	scanf("%d", &n);
    	while (n --> 0) {
    		char op;
    		scanf("%1s", &op);
    		if (op == 'A') {
    			int a, b, res = 0;
    			scanf("%d%d", &a, &b);
    			Interval now(a, b);
    			std::set<Interval>::iterator it = S.find(now);
    			while (it != S.end()) {
    				S.erase(it);
    				res++;
    				it = S.find(now);
    			}
    			S.insert(now);
    			printf("%d
    ", res);
    		} else printf("%llu
    ", S.size());
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    第二次结对编程作业
    第5组 团队展示
    第一次结对编程作业
    BETA 版冲刺前准备(团队)
    项目测评(团队)
    1111111111
    Alpha 事后诸葛亮
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/10172567.html
Copyright © 2011-2022 走看看