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

    这一题是用来练习stl的,,,
    stl的set固然很方便, 但是在c++98里erase好像是没有返回值的, 不能像c++11一样

    it = S.erase(it);
    

    所以c++98里删掉以后最好重新找以防RE.
    具体在这道题中, 就是每一次lower_bound以后看看能不能删前面的或者后面的.
    c++98真是反人类啊...什么时候noip能够用c++11呢.

    #include <set>
    #include <cstdio>
    #include <cstring>
    #include <cassert>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    typedef pair<int, int> P;
    const int MAXN = 200000 + 10;
    inline int read(){
        char ch = getchar(); int x = 0;
        while(!isdigit(ch)) ch = getchar();
        while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
        return x;
    }
    
    int N;
    set<P> S;
    
    int main(){
        // freopen("p2161.in", "r", stdin);
        // freopen("p2161.out", "w", stdout);
        cin>>N;
        while(N--) {
            char opt; scanf(" %c", &opt);
            if(opt == 'A') {
                int l = read(), r = read();
                P cur = P(l, r); int cnt = 0;
                set<P>::iterator it;
                while(true) {
                    it = S.lower_bound(cur); bool flag = false;
                    if(it->first <= r && it->second >= l) 
                        ++cnt, S.erase(it), flag = true;
                    it = S.lower_bound(cur);
                    if(it != S.begin()) {
                        --it; 
                        if(it->first <= r && it->second >= l) 
                            ++cnt, S.erase(it), flag = true;
                    }
                    if(!flag) break;
                }
                S.insert(cur); printf("%d
    ", cnt);
            }
            else printf("%d
    ", (int)S.size());
        }
        return 0;
    }
    
  • 相关阅读:
    特征方程
    鸽巢原理
    Python列表与字典
    布尔型
    python字符串
    Python小笔记
    IntelliJ 中Maven pom.xml依赖不生效解决
    IDEA创建servlet,篇末有找不到servlet报404的原因
    jQuery的ajax之验证用户名是否被注册
    jquery之Validata表单验证
  • 原文地址:https://www.cnblogs.com/wsmrxc/p/9908343.html
Copyright © 2011-2022 走看看