zoukankan      html  css  js  c++  java
  • uva11020 set

    有n个人,每个人有两个属性x,y。如果对于一个人P(x,y) 不存在另外一个人(x',y') 使得x'<x,y'<=y 或者 x'<=x,y'<y 我们说p是有优势的,每次给出一个人的信息,要求输出在只考虑当前已获得信息的前提下,多少人是有优势的。

    set 可以用lower_bound 把点插入,然后不断的去修改。

    #include <iostream>
    #include <cstdio>
    #include <set>
    using namespace std;
    struct point{
       int x , y ;
       bool operator < ( point A)const {
          return x<A.x||(x==A.x&&y<A.y);
       }
    };
    multiset<point> S;
    multiset<point>::iterator it;
    int main()
    {
        int T;
        scanf("%d",&T);
        for(int kase=1; kase<=T; ++kase){
             if(kase>1) printf("
    ");
             printf("Case #%d:
    ",kase);
              int n,a,b;
              scanf("%d",&n);
              S.clear();
              while(n--){
                   scanf("%d%d",&a,&b);
                   point p = (point){a,b};
                   it=S.lower_bound(p);
                   if(it==S.begin()||(--it)->y>p.y){
                      S.insert(p);
                      it=S.upper_bound(p);
                      while(it!=S.end()&&it->y>=p.y)S.erase(it++);
                   }
                   printf("%d
    ",S.size());
              }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    C#不显示在任务栏
    打开文件,文件夹
    C#文本操作
    C#路径2
    C#当前程序路径获取
    HDU 5155 Harry And Magic Box dp
    POJ 1971 Parallelogram Counting
    CodeForces 479C Exams 贪心
    CodeForces 508E Arthur and Brackets 贪心
    CodeForces 483B 二分答案
  • 原文地址:https://www.cnblogs.com/Opaser/p/4197593.html
Copyright © 2011-2022 走看看