Alice and Bob

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2869    Accepted Submission(s): 926
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
 
Source
 

题意:一个物品有两个參数x,y,当且仅当a物品的x不小于b物品的x且a物品的y不小于b物品的y时a物品能覆盖b物品。如今有个a物品的集合和b物品的集合,问a集合最多能覆盖多少个b集合中的物品。

题解:对两个集合依照x进行升序排序,然后对a集合中的每一个物品,在x满足的情况下。将相应的b集合中的物品扔入multiset中,然后在multiset中寻找y值最大的合法值,若找到++ans并将该值erase;

#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std; #define maxn 100010
#define inf 0x7fffffff struct Node {
int x, y;
} A[maxn], B[maxn];
int n; bool cmp(Node a, Node b) {
return a.x < b.x;
} int main() {
int t, i, j, ans;
scanf("%d", &t);
while(t--) {
multiset<int> mst;
multiset<int>::iterator it;
scanf("%d", &n);
for(i = 0; i < n; ++i)
scanf("%d%d", &A[i].x, &A[i].y);
for(i = 0; i < n; ++i)
scanf("%d%d", &B[i].x, &B[i].y);
sort(A, A + n, cmp);
sort(B, B + n, cmp);
ans = 0;
for(i = j = 0; i < n; ++i) {
for( ; j < n && A[i].x >= B[j].x; ++j) {
mst.insert(B[j].y);
}
if(mst.empty()) continue;
it = mst.lower_bound(A[i].y);
if(*--it <= A[i].y) {
++ans; mst.erase(it);
}
}
printf("%d\n", ans);
}
return 0;
}

HDU4268 Alice and Bob 【贪心】的更多相关文章

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

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

  2. Alice and Bob(贪心HDU 4268)

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

  3. HDU 4268 Alice and Bob 贪心STL O(nlogn)

    B - Alice and Bob Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  4. HDU 4268 Alice and Bob(贪心+Multiset的应用)

     题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...

  5. hdu 4268 Alice and Bob(multiset|段树)

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

  6. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

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

  7. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  8. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  9. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

随机推荐

  1. 【Android 面试基础知识点整理】

    针对Android面试中常见的一些知识点整理,Max 仅仅是个搬运工.感谢本文中引用文章的各位作者,给大家分享了这么多优秀文章.对于当中的解析,是原作者个人见解,有错误和不准确的地方,也请大家积极指正 ...

  2. 将 php 转换/编译为 EXE

    将 php 转换/编译为 EXE 本文仅仅是将原文用谷歌作了翻译,原文来源于 http://stackoverflow.com 资料来源  http://stackoverflow.com/quest ...

  3. ubuntu-smb共享文件创建

    如何在计算机上实现资源共享                         --在本地用户目录下,创建一个smb文件夹                         --右击,选择share opt ...

  4. Android JSON数据解析(GSON方式)

    要创建和解析JSON数据,也可以使用GSON来完成.GSON是Google提供的用来在Java对象和JSON数据之间进行映射的Java类库.使用GSON,可以很容易的将一串JSON数据转换为一个Jav ...

  5. POJ 1654 Area 凸包面积

    水题直接码... /********************* Template ************************/ #include <set> #include < ...

  6. 非常不错的canvas效果,线随心动

    非常不错的canvas效果,下面是html代码. <!DOCTYPE html> <html> <head> <meta charset="utf- ...

  7. CF #261 div2 D. Pashmak and Parmida&#39;s problem (树状数组版)

    Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants he ...

  8. VPS的centOS6安装远程桌面

    VPS的centOS6安装远程桌面 64位系统的需要编译安装 ttp://www.landui.com/help/Show-991.html xrdp是在图形界面下使用的,首先要确定您的centos系 ...

  9. 关于hadoop hdfs里文件为啥上一级大小是0,进去又有大小问题解释?

    问题 好像跟平时的理解不一样,外边是0,进去就是有大小了? 答:hdfs具体文件是针对具体文件的,不是文件目录.    文件夹大小为0,不是里面所有内容为0.

  10. Android 6.0 最简单的权限获取方法 RxPermition EasyPermition

    Android 6.0 要单独的获取权限 这里提供两种很简单的方法 EasyPermition RxPermition EasyPermition https://github.com/googles ...