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("\n");
         printf("Case #%d:\n",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\n",S.size());
          }
    }
    return 0;
}
View Code

 

posted @ 2015-01-01 19:28  来自大山深处的菜鸟  阅读(143)  评论(0编辑  收藏  举报