UVA11020 Efficient Solutions

维护一个集合,包含当前状态所有优势人群,则当前集合中元素一定呈“下凹函数”形态
每插入一个点P,比较P点与左侧相邻点y坐标,若P点y坐标大于左侧相邻点y坐标,则忽略(P点无优势),否则插入P点,将相对于P点无优势的点从集合中删除。删除点一定位于P点右上方。
查找过程使用STL中lower_boundupper_bound函数

#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <stdio.h> 

using namespace std;

struct Point{
    int x, y;
    bool operator < (const 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 i = 1; i <= T; i++){
        if(i > 1)   printf("\n");
        printf("Case #%d:\n", i);
        s.clear();
        int n;
        scanf("%d", &n);
        while(n--){
            int a, b;
            scanf("%d%d", &a, &b);
            Point P = (Point) {a, b};
            it = s.lower_bound(P);
            if(it == s.begin() || (--it) -> y > b){
                s.insert(P);
                it = s.upper_bound(P);
                while(it != s.end() && it -> y >= b)    s.erase(it++);
            }
            printf("%d\n", s.size());
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值