Alice and Bob(贪心HDU 4268)
Alice and Bob
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3716 Accepted Submission(s): 1179
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
2012 ACM/ICPC Asia Regional Changchun Online
贪心的策略,先进行排序,(两个元素谁优先都一样),对bo[i].y(Bob)进行查找,找到最接近al[i].y(Alice)的值,删除他。
#include <iostream>
#include <set>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int MAX=101000;
struct node
{
int w;
int h;
bool operator <(const node &a)const//重载小于号
{
if(w<a.w||(w==a.w&&h<a.h))
{
return true;
}
return false;
}
}al[MAX],bo[MAX];
multiset<int>st;
int main()
{
int n;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
st.clear();
for(int i=0;i<n;i++)
{
scanf("%d %d",&al[i].h,&al[i].w);
}
for(int i=0;i<n;i++)
{
scanf("%d %d",&bo[i].h,&bo[i].w);
}
sort(al,al+n);
sort(bo,bo+n);
int ans=0;
int j=0;
multiset<int>::iterator it;
for(int i=0;i<n;i++)
{
while(j<n&&bo[j].w<=al[i].w)//将al[i]可能覆盖的放在set中
{
st.insert(bo[j].h);
j++;
}
if(st.empty())
{
continue;
}
it=st.lower_bound(al[i].h);//二分查找
if(*it==al[i].h)//删除
{
ans++;
st.erase(it);
}
else
{
if(it!=st.begin())//如果返回第一个比它大的
{
st.erase(--it);//删除后面的
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}
Alice and Bob(贪心HDU 4268)的更多相关文章
- 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 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
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- Alice and Bob HDU - 4268
Alice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N ...
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- hdu 4111 Alice and Bob 记忆化搜索 博弈论
Alice and Bob Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 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 ...
随机推荐
- MongoDB(一):安装
安装 从度娘上搜索MongoDB,找到官网地址:https://www.mongodb.com 找到下载中心地址:https://www.mongodb.com/download-center 我下载 ...
- java 线上问题定位工具
在JDK的bin目录下有很多命令行工具: 我们可以看到各个工具的体积基本上都稳定在27kb左右,这个不是JDK开发团队刻意为之的,而是因为这些工具大多数是jdk\lib\tools.jar类库的一层薄 ...
- JSTL 核心标签库
SP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了这些,它还提供了 ...
- 实验十三_编写、应用中断例程_2 & 总结
编写并安装int 7ch中断例程,功能为完成loop指令的功能 参数:(cx)= 循环次数,(bx)= 位移 以上中断例程安装成功后,对下面的程序进行单步跟踪,尤其注意观察int.iret指令执行前后 ...
- SQL查询一个表的总记录数的方法
一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指定列 SQL>SELECT empmo, ...
- bzoj3489 A simple rmq problem 可持久化树套树
先预处理出两个个数组pre,next.pre[i]表示上一个与i位置数字相同的位置,若不存在则设为0:next[i]表示下一个与i位置数字相同的位置,若不存在则设为n+1.那么一个满足在区间[L,R] ...
- Android 仿土巴兔选择效果
1,前两天在群里看到有人在讨论土巴兔的选择装修风格的效果,自己也想实现,果断百度一下,有些好的文章,就花了些时间来分析了下,先看看别人土巴兔原装的功能 2,可以看到,基本上可以使用一个vviewpag ...
- 夺命雷公狗—angularjs—6—单条数据的遍历
我们在实际的工作中常常会处理到一些数据的遍历,这些数据都是后端传到前端的,有些公司会让前端帮忙处理一点遍历的工作,废话不多说,直接上代: <!doctype html> <html ...
- 夺命雷公狗ThinkPHP项目之----企业网站8之栏目的添加完善(无限极分类的完成)
我们刚才只是完成了添加的一部分,但是我们的上级分类也不能永远都是只有一个死的嘛,所以我们需要对她进行修改: 我们先将add方法里面的数据查出来再说: 然后在模板页进行遍历: 展示效果如下所示: 虽然是 ...
- z/os上的tar和gzip
在*nix平台上玩过的人都知道,tar和gzip基本上是每天都要使用的,而且非常之好用.而Mainframer则比较痛苦,没有这么好用的东西,尤其是当需要通过网络传大批量的文件的时候很不方便. 不过总 ...