zoukankan      html  css  js  c++  java
  • STL(multiset) UVA 11020 Efficient Solutions

    题目传送门

    题意:训练指南P228

    分析:照着书上的做法,把点插入后把它后面不占优势的点删除,S.size ()就是优势的人数,时间复杂度O (nlogn)

    #include <bits/stdc++.h>
    using namespace std;
    
    struct Point    {
        int a, b;
        Point() {}
        Point(int a, int b) : a (a), b (b)  {}
        bool operator < (const Point &r) const  {
            return (a < r.a || (a == r.a && b < r.b));
        }
    };
    multiset<Point> S;
    multiset<Point>::iterator it;
    
    int main(void)  {
        int T, cas = 0;  scanf ("%d", &T);
        while (T--) {
            S.clear ();
            printf ("Case #%d:
    ", ++cas);
            int n;  scanf ("%d", &n);
            for (int x, y, i=1; i<=n; ++i)  {
                scanf ("%d%d", &x, &y);
                Point p (x, y);
                it = S.lower_bound (p);
                if (it == S.begin () || (--it) -> b > y)    {
                    S.insert (p);
                    it = S.upper_bound (p);
                    while (it != S.end () && it -> b >= y)  S.erase (it++);
                }
                printf ("%d
    ", S.size ());
            }
            if (T)  puts ("");
        }
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    书籍阴影
    Cookie工具类
    兼容性问题总结
    pc端弹框
    懒加载 js----例子------图片
    pc端样式初始化
    Sublime 插件- px 转rem
    手机端1px细线公共类
    移动端样式初始化
    SQL Server(七)——存储过程
  • 原文地址:https://www.cnblogs.com/Running-Time/p/5123793.html
Copyright © 2011-2022 走看看