uva11020 Efficient Solutions mutiset

来源:互联网 发布:java变量重新赋值 编辑:程序博客网 时间:2024/05/16 05:45

题意:有n个人,每个人有两个属性x,y。对于一个人P(x,y),不存在另一个人P(x',y'),使得x'<x,y'<=y,活着x'<=x,y'<y,窝们说P有优势

的,每次给出一个人的信息,输出当前多少人是有优势的。

思路:窝们考虑用multiset维护,元素先按x升序,再按y升序排列。插入一个点时,判断它左边相邻点的y坐标是否比它小,如果比它

大则该点有优势。加入multiset后,它会让一些点失去优势,从upper_bound开始到end大于等于它的y值的点都删去。详见代码:

/*********************************************************  file name: uva11020.cpp  author : kereo  create time:  2015年01月25日 星期日 16时02分36秒*********************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<set>#include<map>#include<vector>#include<stack>#include<cmath>#include<string>#include<algorithm>using namespace std;typedef long long ll;const int sigma_size=26;const int N=100+50;const int MAXN=100000+50;const int inf=0x3fffffff;const double eps=1e-8;const int mod=100000000+7;#define L(x) (x<<1)#define R(x) (x<<1|1)#define PII pair<int, int>#define mk(x,y) make_pair((x),(y))int n;bool operator < (const PII & a,const PII & b){    if(a.first == b.first)        return a.second < b.second;    return a.first < b.first;}multiset<PII>mp;multiset<PII>::iterator it;int main(){    int T,kase=0;    scanf("%d",&T);    while(T--){        if(kase)            printf("\n");        printf("Case #%d:\n",++kase);        scanf("%d",&n);        mp.clear();        int x,y;        while(n--){            scanf("%d%d",&x,&y);            PII tmp=make_pair(x,y);            it=mp.lower_bound(tmp);            if(it == mp.begin() || (--it)->second > tmp.second){                mp.insert(tmp);                it=mp.upper_bound(tmp);                while(it!=mp.end() && it->second >= tmp.second)                    mp.erase(it++);            }            printf("%d\n",mp.size());        }    }return 0;}


0 0
原创粉丝点击