Alice and Bob HDU - 4268
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的更多相关文章
- 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 ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- Alice and Bob(贪心HDU 4268)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 4268 Alice and Bob(multiset|段树)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 4268 Alice and Bob 贪心STL O(nlogn)
B - Alice and Bob Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...
- hdu 4111 Alice and Bob 记忆化搜索 博弈论
Alice and Bob Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 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 ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
随机推荐
- BZOJ 3997: [TJOI2015]组合数学 [偏序关系 DP]
3997: [TJOI2015]组合数学 题意:\(n*m:\ n \le 1000\)网格图,每个格子有权值.每次从左上角出发,只能向下或右走.经过一个格子权值-1.至少从左上角出发几次所有权值为0 ...
- python爬虫(4)——正则表达式(一)
在前几篇文章中我们使用了python的urllib模块,做了一些访问网页的工作.现在介绍一个非常强大的工具--正则表达式.在讲述正则的时候,我参考了<精通正则表达式(第三版) ---Je ...
- 浅讲JUnit
JUnit单元简介: JUnit ----是一个开发源码的java测试框架,用于编写和运行可重复的测试,它是用于单元测试框架体系xUnit的一个实例, 用于java语言,主要用于白盒测试,回 ...
- Project support for both iOS 6 and iOS 7
原文:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/S ...
- php使用file_get_contents请求微信接口失败
windows下的php,只需要到php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了.Linux下的PHP,就必须安装openssl模块,安装好了以后就 ...
- 【阿里聚安全·安全周刊】科学家警告外星恶意代码|新方法任意解锁iPhone
本周的七个关键词: 外星恶意代码 丨 任意解锁iPhone 丨 安卓9.0 丨 黑客攻击医疗设备 丨 仙女座僵尸网络 丨 苹果联合创始人被骗比特币 丨JavaScript -1- [恶意代码] ...
- Java.lang.Comparable接口和Java.util.Comparator接口的区别
Java的Comparator和Comparable当需要排序的集合或数组不是单纯的数字型时,通常可以使用Comparator或Comparable,以简单的方式实现对象排序或自定义排序. 1.Com ...
- 原创:实现ehcache动态创建cache,以及超期判断的具体逻辑
当前最常用的三个缓存组件:ehcache.redis.memcached 其中,ehcache与应用共同运行于JVM中,属于嵌入式组件,运行效率最高,因此常被用于实现一级缓存. 在更复杂的一些系统中, ...
- window 环境变量保存位置在哪里?
注册表-regedit.exe 用户变量: HKEY_CURRENT_USER\Environment 系统变量: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe ...
- UVA - 10723 类似LCS
思路:dp(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串长度,cnt(i, j)表示第一个串前i个字符和第二个串前j个字符需要的最短字符串的个数. 转移方程: if(s1[i] ...