Problem Description
Alice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N different rectangular cards respectively. Alice wants to use his cards to cover Bob's. The card A can cover the card B if the height of A is not smaller than B and the width of A is not smaller than B. As the best programmer, you are asked to compute the maximal number of Bob's cards that Alice can cover.
Please pay attention that each card can be used only once and the cards cannot be rotated.
 
Input
The first line of the input is a number T (T <= 40) which means the number of test cases. 
For each case, the first line is a number N which means the number of cards that Alice and Bob have respectively. Each of the following N (N <= 100,000) lines contains two integers h (h <= 1,000,000,000) and w (w <= 1,000,000,000) which means the height and width of Alice's card, then the following N lines means that of Bob's.
 
Output
For each test case, output an answer using one line which contains just one number.
 
Sample Input
2
2
1 2
3 4
2 3
4 5
3
2 3
5 7
6 8
4 1
2 5
3 4
 
Sample Output
1
2
 

题义大概就是A有一些卡片,B有一些卡片,A的卡片能覆盖B卡片最多多少张(只有长和宽同时大于等于才行)

#include <bits/stdc++.h>
using namespace std;
#define Maxn 100010

struct Node{
    int x,y,id;
};
Node G[Maxn*2];

bool cmp(Node n1,Node n2){
    if(n1.x == n2.x && n2.y == n2.y) return n1.id > n2.id;
    //这里注意排序方式
    if(n1.x != n2.x) return n1.x > n2.x;
    return n1.y > n2.y;
}

int main()
{
    int N;
    cin >> N;
    while(N--){
        int n,t;
        cin >> n;
        for(int i = 0; i <(n<<1); i++){
            scanf("%d%d",&G[i].x,&G[i].y);
            if(i < n){
                G[i].id = 1;
            }else{
                G[i].id = 0;
            }
        }
        sort(G,G+(n<<1),cmp);
        multiset<int>s;
        int cnt = 0;
        for(int i = 0; i < (n<<1); i++){
            // 这里用了贪心的方法,因为已经排序了,按照从x从小到大的顺序
            // 如果是A,放入容器,如果是B,就从A中找到比B大的中的最小的(贪心)
            if(G[i].id){
                s.insert(G[i].y);
            }else{
                multiset<int>::iterator it = s.lower_bound(G[i].y);
                if(it == s.end() || *it < G[i].y){
                    // 这步判断很重要
                    continue;
                }else{
                    cnt++;
                    s.erase(it);
                    // 找到就删掉,以后都不再用了
                }
            }
        }
        printf("%d\n",cnt);
    }
}

  

贪心+容器 hdu4268的更多相关文章

  1. hdu4864 hdu4268 贪心 lower_bound

    hdu4864 题意: 有n个机器,m个任务,n,m<=100000,每个机器都有工作时间的最大限制xi(0<xi<1440)和完成的最大难度yi(0<=yi<=100) ...

  2. 【LeetCode】盛最多水的容器【双指针+贪心 寻找最大面积】

    给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线, ...

  3. HDU4268 Alice and Bob(贪心+multiset)

    Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...

  4. hdu4268贪心

    题意:       两个人有一些图片,矩形的,问a最多能够覆盖b多少张图片.. 思路:       明显是贪心,但是有一点很疑惑,如果以别人为主,每次都用自己最小的切能覆盖敌人的方法就wa,而以自己为 ...

  5. Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)

    A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. HDU4268 Alice and Bob 【贪心】

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. STL容器的本质

    http://blog.sina.com.cn/s/blog_4d3a41f40100eof0.html 最近在学习unordered_map里面的散列函数和相等函数怎么写.学习过程中看到了一个好帖子 ...

  8. LeetCode(11):盛最多水的容器

    Medium! 题目描述: 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, ...

  9. 【NOI2015】荷马史诗[Huffman树+贪心]

    #130. [NOI2015]荷马史诗 统计 描述 提交 自定义测试 追逐影子的人,自己就是影子. ——荷马 Allison 最近迷上了文学.她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读 ...

随机推荐

  1. 网络编程(学习整理)---3--(Udp)FeiQ实现广播消息群发

    1.广播群发消息: 这里使用的任然是UDP协议,使用方法还是比较简单的! 我就记录一下需要注意的一些地方(笔记): (1)这里是在局域网内,借用FeiQ聊天软件,编写一段程序,实现对局域网内的每一个登 ...

  2. jquery 之选择符

    css:选择符$('#selected-plays > li') 使用了子元素组合符,查找 ID 为 selected-plays 的元素的子元素( > )中所有的列表 li$('#sel ...

  3. laravel学习:修改时区

    config/app.php 'timezone' => 'UTC', 改为 'timezone' => 'PRC',

  4. python读取excel文件

    一.xlrd的说明 xlrd是专门用来在python中读取excel文档的模块,使用前需要安装. 可以到这https://pypi.python.org/pypi/xlrd进行下载tar.gz文件,然 ...

  5. 结合rpyc使用python实现动态升级的方法

    动态升级,就是程序不退出的情况下,将其代码更新的策略.假设集群含有多个机器,然后每个机器部署一套程序,当升级的时候就要去所有的上面部署一把. (1)有个包装程序专门负责接口并检查是否需要更新,当需要更 ...

  6. 常见HTTP状态码大全

    我们经常会遇到404.500.302等提示,它们究竟是什么意思呢?除了这几个常见的状态码外,还有哪些我们没有遇到过的但有可能出现的状态码呢?网站的http状态对于网站维护人员来说是相当重要的,当网站出 ...

  7. Java实现Http服务器(二)

    上节讲到的JDK自带的HttpServer组件,实现方法大概有三十个类构成,下面尝试着理解下实现思路. 由于Java的source代码中有很多注释,粘贴上来看着费劲,自己写个程序消除注释. impor ...

  8. UI设计网站参考

    1. https://dribbble.com/colors/6A969A 2. 设计师网站导航:http://hao.uisdc.com/ 3. bootstrap的UI:http://www.bo ...

  9. ios7控件特性(一)

    苹果发布iOS7之后,iOS7全部采用扁平化的界面,我们的app界面在iOS7上出现了很大的改变,这包括UINavigationBar,UIButton,UIActionSheet,UITabBar等 ...

  10. PHP 如何安全的使用 MySQL ?

    大多数 PHP 程序员对 MySQL 肯定不陌生,至于各种 MySQL 函数的用法在开发手册和 w3school 这类网站上也有很多介绍.但是,你所用的写法真的安全吗?面对越来越猖獗的黑客攻击,SQL ...