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

    题目传送门

    嗯,这道题的标签是STL,因为这个STL用的确实太妙了


    这道题目要求维护一堆区间,而一个重要的操作是要删除所有与新区间冲突的区间

    虽然可以用(Splay)来操作,但用STL里的set也绝对不虚
    其中最精妙的当属这个重载运算符
    它的意思是当两个区间相交时,这两个区间相等

    struct zzz {
        int l, r;
        bool operator < (const zzz &y) const { return r < y.l; }
    }; set <zzz> q;
    

    重载完运算符,再凭借set的find函数,就可以很容易的通过此题

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <set>
    #define LL long long
    using namespace std;
    LL read() {
        LL k = 0; char c = getchar();
        while(c < '0' || c > '9') c = getchar();
        while(c >= '0' && c <= '9')
            k = k * 10 + c - 48, c= getchar();
        return k;
    }
    char read_c() {
        char c = getchar();
        while(c != 'A' && c != 'B') c = getchar();
        return c;
    }
    struct zzz {
        int l, r;
        bool operator < (const zzz &y) const { return r < y.l; }
    }; set <zzz> q;
    int main() {
        int m = read();
        while(m--) {
            char opt = read_c();
            if(opt == 'A') {
                int l = read(), r = read(), cnt = 0;
                zzz k = (zzz){l, r};
                set<zzz> :: iterator it = q.find(k);
    			//将相交的区间全都删去
                while(it != q.end()) {
                    ++cnt; q.erase(it);
                    it = q.find(k);
                }
                q.insert(k);
                printf("%d
    ", cnt);
            }
            else printf("%d
    ", q.size());
            
        }
        return 0;
    }
    
  • 相关阅读:
    LNMP一键安装
    IIS出现问题报CS0016
    如何在windows live Write中添加插件
    合同管理系统 功能一览表
    房地产合同档案分类及编号规则
    属性ErrorLogFile不可用于JobServer的解决方案
    Wps定义选中区域的名称
    常用的SQL语句
    xp sp3 访问IIS元数据库失败解决办法
    完全卸载oracle11g步骤
  • 原文地址:https://www.cnblogs.com/morslin/p/11855286.html
Copyright © 2011-2022 走看看