Uva 11120 Efficient Solutions

来源:互联网 发布:模拟期权交易软件 编辑:程序博客网 时间:2024/05/17 06:19

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1961

本题题意是求每一次查询的优势的人数,我们可以用现成的multiset代替原本的平衡树。

mulitse可以存储相同的两个元素。排序方式可以自定义。

#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <set>using namespace std;struct Point{    int x,y;    Point(int _x,int _y)    {        x = _x;        y = _y;    }    bool operator < (const Point & rhs) const    {        return x < rhs.x || (x == rhs.x && y < rhs.y);    }};multiset<Point> S;multiset<Point>::iterator it;int main(){#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);#endif    int t;    int n;    int x,y;    int cas = 0;    scanf(" %d",&t);    while(t--)    {        cas++;        printf("Case #%d:\n",cas);        S.clear();        scanf(" %d",&n);        for(int i=0;i<n;i++)        {            scanf(" %d %d",&x,&y);            Point a(x,y);            it = S.lower_bound(a);            if(it == S.begin() || (--it)->y > y )            {                S.insert(a);                it = S.upper_bound(a);                while(it!=S.end() && it->y >= y)                {                    S.erase(it++);                }            }            printf("%d\n",S.size());        }        if(t!=0) puts("");    }    return 0;}


原创粉丝点击