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 3262: 陌上花开 [CDQ分治 三维偏序]
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- 解决asp.net MVC中 当前上下文中不存在名称“model” 的问题
在vs2013下打开同事上传的cshtml视图文件报错,出现当前上下文中不存在名称“model”,ViewBag,Url等等,在视图中也没有智能提示了:但是不影响编译运行,只是开发时候比较麻烦,但在同 ...
- 关于node的基础理论,书上看来的
最近看了一本书,说了一些Node.js的东西,现在来记录一下,让自己记得更牢靠一点. 在书上,是这样介绍的:Node.js模型是源于Ruby的Event Machine 和 Python的Twiste ...
- solr-搭建与使用过程中问题总结-链接
以下错误可以确定在CDH版本Hbase集群+Lily hbase indexer+solrCloud的环境中可以解决,有开源版本解决成功案例的请在下方评论. 1.If you see this err ...
- spring boot学习资源
http://blog.csdn.net/u014695188/article/details/52226134 http://www.jianshu.com/p/887c22723e43 Sprin ...
- python并发编程之多进程(二):互斥锁(同步锁)&进程其他属性&进程间通信(queue)&生产者消费者模型
一,互斥锁,同步锁 进程之间数据不共享,但是共享同一套文件系统,所以访问同一个文件,或同一个打印终端,是没有问题的, 竞争带来的结果就是错乱,如何控制,就是加锁处理 part1:多个进程共享同一打印终 ...
- 新手最纠结的事。学什么语言最好?学什么语言有前途(or 钱途)?
这篇文章是转载自王根的博客,源地址:http://www.yinwang.org/blog-cn/2017/07/06/master-pl ,虽然王根是一个备受争议的人,不过这篇文章写的很好,我对于编 ...
- Yii中DataProvider的使用
1,DataProvider 什么是数据提供者 数据提供者可以获取数据,并提供给其他组件或页面使用 可以获得列的数据进行分页和排序 经常用来给数据小部件提供数据,方便用户互动地进行数据的分页与排序 实 ...
- Git版本控制的基本命令
安装完了GIT首先要自报家门,否则代码不能提交 git config --global user.name "Your Name" git config --global user ...
- Qt msvc 乱码如何解决?
#ifdef Q_OS_WIN #pragma execution_character_set("UTF-8") #endif