HDU4268 Alice and Bob 【贪心】
Alice and Bob
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.
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.
2
2
1 2
3 4
2 3
4 5
3
2 3
5 7
6 8
4 1
2 5
3 4
1
2
题意:一个物品有两个參数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 【贪心】的更多相关文章
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- 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 贪心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 ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
随机推荐
- [LuoguP4892]GodFly的寻宝之旅 状压DP
链接 基础状压DP,预处理出sum,按照题意模拟即可 复杂度 \(O(n^22^n)\) #include<bits/stdc++.h> #define REP(i,a,b) for(in ...
- thinkphp图片处理
thinkphp图片处理 一.总结 1.参考手册:参考手册上面啥都有,只是这样业务逻辑不明显,所以看视频会很好,但是如果用编程的灵性(设计),那么其实会更加高效,但是看视频更快而且没那么枯燥,更高效把 ...
- iTOP-4412开发板p2p视频
整体框架: 一.发送端 1.摄像头通过V4L2接口得到YUV视频格式,可以在win7上用yuvplayer播放 2.使用4412硬件编码模块MFC提供的接口进行硬件编码,得到.264文件,可以在win ...
- Bitmap-把方形图片处理为圆形
这个是直接在网上转载的,自己验证可靠 转载自http://my.oschina.net/zhouz/blog/213164 直接贴上代码 import android.graphics.Bitmap; ...
- ASP.NET MVC案例教程(基于ASP.NET MVC beta)——第三篇:ASP.NET MVC全局观
摘要 本文对ASP.NET MVC的全局运行机理进行一个简要的介绍,以使得朋友们更好的理解后续文章. 前言 在上一篇文章中,我们实现了第一个ASP.NET MVC页面.对于没有接触 ...
- Altium Designer如何删除以布的线
- (转)xshell无法在vim中复制黏贴
ssh xshell 连接在vim中无法用 ctrl+insert 复制黏贴 修改.vimrc set mouse=c vi的三种模式:命令模式,插入模式,可视模式.鼠标可以启动于各种模式中: The ...
- Spring+Struts2+Hibernate的整合
这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形 ...
- jni和C++通信中文乱码的问题
转自 http://www.cnblogs.com/bluesky4485/archive/2011/12/13/2285802.html 首先,需要明确几个关于编码的基本概念: java内部是使用的 ...
- Python内部机制-PyObject对象
PyObject对象机制的基石 学过Python的人应该非常清晰,Python中一切都是对象,全部的对象都有一个共同的基类,对于本篇博文来说,一切皆是对象则是探索Python的对象机制的一个入口点.我 ...