hdu 4268

巨坑无比的题目,有人连样例都过不去还真给他过了,真的坑,这题就姑且看一下,反正很奇怪的贪心,但是不能用pair,因为不能保证全部大于,巨坑

#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;

const int MAX=100000*2+100;
struct rectangular
{
    int h,w,bel;
}Rect[MAX];
multiset<int>MulSet;
multiset<int>::iterator iter;

bool cmp1(rectangular a,rectangular b)
{
    if(a.h!=b.h)
        return a.h<b.h;
    else if(a.w!=b.w)
        return a.w<b.w;
    else 
        return a.bel>b.bel;//保证来一个Alice的方块后它能覆盖的Bob的方块已出现
}


int main()
{
    int cas,i,n,ans;
    cin>>cas;
    while(cas--)
    {
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&Rect[i].h,&Rect[i].w);
            Rect[i].bel=1;
        }

        for(i=n;i<2*n;i++)
        {
            scanf("%d%d",&Rect[i].h,&Rect[i].w);
            Rect[i].bel=2;
        }

        MulSet.clear();
        ans=0;
        sort(Rect,Rect+2*n,cmp1);
        for(i=0;i<2*n;i++)
        {
            if(Rect[i].bel==1)
            {
                if(!MulSet.empty())
                {
                     iter=MulSet.begin();
                    if(Rect[i].w>=(*iter))
                    {
                        ans++;
                        iter=MulSet.upper_bound(Rect[i].w);//关键字大于Rect[i].w的第一个
                        iter--;//保证删除小于等于Rect[i].w的MulSet中最大的元素
                         MulSet.erase(iter);
                    }
                }
            }
            else
            {
                MulSet.insert(Rect[i].w);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/coolwx/p/11129933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值