码迷,mamicode.com
首页 > 其他好文 > 详细

uva11020 set

时间:2015-01-01 19:43:28      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

有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

 

uva11020 set

标签:

原文地址:http://www.cnblogs.com/Opaser/p/4197593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!