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. 

InputThe 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. 
OutputFor 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

爱丽丝和鲍勃的游戏永远不会结束。 今天,他们推出了一款新游戏。 在这场比赛中,他们两人分别拥有N张不同的矩形牌。 爱丽丝想用他的卡片来掩护鲍勃的。 如果A的高度不小于B并且A的宽度不小于B,则卡A可以覆盖卡B.作为最好的程序员,要求您计算Alice可以覆盖的鲍勃卡的最大数量。
请注意,每张卡只能使用一次,卡不能旋转。

通过这题学习了一个新的数据结构multiset

这个数据结构完美的切合题目意思

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
#include<set>
using namespace std; struct node
{
int w,h;
}a[],b[];
int cmp(node c,node d)
{
return c.w<d.w;
}
multiset<int>m;
multiset<int>::iterator it; int main() {
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for (int i= ;i<n ;i++){
scanf("%d%d",&a[i].w,&a[i].h);
}
for (int i= ;i<n ;i++){
scanf("%d%d",&b[i].w,&b[i].h);
}
int ans=;
sort(a,a+n,cmp);
sort(b,b+n,cmp);
m.clear();
for (int i= ,j= ; i<n ;i++){
while(j<n&&a[i].w>=b[j].w) {
m.insert(b[j++].h);
}
if(m.empty()) continue;
it = m.upper_bound(a[i].h);
if(it != m.begin()) {
it--;
m.erase(it);
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

Alice and Bob HDU - 4268的更多相关文章

  1. Alice and Bob HDU - 4111 (SG函数)

    Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The ...

  2. hdu 4268 Alice and Bob

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

  3. Alice and Bob(贪心HDU 4268)

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

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

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

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

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

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

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

  7. hdu 4111 Alice and Bob 记忆化搜索 博弈论

    Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. hdu 3660 Alice and Bob's Trip(树形DP)

    Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. 洛谷 [P1387] 最大正方形

    本题非常有趣. (n^6) 枚举四个端点,每次遍历矩阵求解. (n^4) 先处理前缀和,枚举四个端点,每次比较前缀和和正方形面积. (n^3) 枚举左上方端点,在枚举边长,前缀和优化 (n^2logn ...

  2. BZOJ 4766: 文艺计算姬 [矩阵树定理 快速乘]

    传送门 题意: 给定一个一边点数为n,另一边点数为m,共有n*m条边的带标号完全二分图$K_{n,m}$ 求生成树个数 1 <= n,m,p <= 10^18 显然不能暴力上矩阵树定理 看 ...

  3. Linux 常用命令 (common commands for linux)

    Linux 常用命令 (Common Commands For Linux) 1.声明,此文章仅写基于 Bash shell 常用的命令,如果遇上命令在使用过程中提示没有,可能随着更新,命令也被替换掉 ...

  4. qt中创建进程

    进程:1.QProcess 进程类 QProcess *a=new QProcess(); 2.启动void QProcess::start(const QString & command, ...

  5. uboot之ldr指令

    刚开始接触uboot的时候,就一直对ldr指令很迷惑,因为这个指令有两层用法,一个是加载,一个是伪指令.今天闲着没事就来说一下这两个之间的区别. LDR伪指令的形式是"LDR Rn,=exp ...

  6. Ubuntu 配置FTP服务器

    第三方的文件传输软件用着很不爽,想着自己搭建一个FTP来干活. 首先检查是否已经安装了FTP,输入命令: vsftpd -v  可以查看版本,如果没有安装,无法执行. 安装FTP p.p1 { mar ...

  7. 💈 A Cross-Thread Call Helper Class

    Conmajia © 2012, 2018 Introduction When you are working on background threads and call frontend GUI ...

  8. ubuntu下boost编译安装

    ubuntu下boost编译安装 boost 安装 1.依赖安装 apt-get install mpi-default-dev libicu-dev python-dev python3-dev l ...

  9. 1.1 Python是一种什么样的语言

    小时不识月,呼作白玉盘.很多人习惯地说Python不过是一种脚本语言而已,实际上这种说法是非常不准确的,完全不能体现出Python的强大.严格来说,Python是一门跨平台.开源.免费的解释型高级动态 ...

  10. LeetCode第二天&第三天

    leetcode 第二天 2017年12月27日 4.(118)Pascal's Triangle JAVA class Solution { public List<List<Integ ...