• HDU 4268 Alice and Bob


    2012长春网络赛1002题
     
    /* 以下内容摘自网络 */
    先按第一维排序,然后第二维
    然后对a的每个i,找出小于a[i].h的b.h,将对应的w塞到集合里
    刚才已经保证了第一维满足了
    然后贪心的从集合里面找a[i]能覆盖的最大的w
     
    代码:
     
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <set>
    using namespace std;

    const int N=100010;
    struct Node{
        int x,y,type;
        bool operator<(const Node &b) const {
            if(x!=b.x) return x<b.x;
            if(y!=b.y) return y<b.y;
            return type>b.type;
        }
    };

    typedef multiset<int> SET;
    typedef multiset<int>::iterator IT;


    Node a[N<<1];
    SET S;
    const int Inf=0x80000000;
    int T,n;


    int main() {
        scanf("%d",&T);
        while(T--) {
            scanf("%d",&n);
            for(int i=0;i<2*n;i++) scanf("%d%d",&a[i].x,&a[i].y);
            for(int i=0;i<n;i++) a[i].type=0;
            for(int i=n;i<n<<1;i++) a[i].type=1;
            sort(a,a+2*n);
            S.clear();
            int ans=0;
            for(int i=0;i<2*n;i++) {
                if(a[i].type==1) S.insert(a[i].y);
                else {
                    if(!S.empty()){
                        if(*S.begin()<=a[i].y){
                            IT it=S.upper_bound(a[i].y);
                            it--;
                            ans++;
                            S.erase(it);
                        }
                    }
                }
            }
            printf("%d\n",ans);
        }
        return 0;
    }
     
  • 相关阅读:
    saltstack笔记
    saltstack学习篇
    tomcat学习篇
    memcache笔记
    sed、awk学习篇
    javascript function call
    jvm性能调优工具
    spring boot 单元测试
    activemq 分布式事务
    sringboot 集成dobbo2.5.3
  • 原文地址:https://www.cnblogs.com/programCaiCai/p/HDU4268.html
Copyright © 2020-2023  润新知