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 ...
随机推荐
- hdu5308 I Wanna Become A 24-Point Master(构造)
题目:pid=5308" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=5308 题意:给定 ...
- “此文件来自其他计算机,可能被阻止以帮助保护该计算机” 教你win7解除阻止程序运行怎么操作
win7 批量解除可执行文件的锁定 "此文件来自其他计算机,可能被阻止以帮助保护该计算机" http://blog.csdn.net/gscsnm/article/details/ ...
- 自定义控件学习——下拉刷新ListView
效果 开始用Android Studio写了,还有挺多不明白这IDE用法的地方....蛋疼 主要思路 1. 添加了自定义的头布局 2. 默认让头布局隐藏setPadding.设置 -自身的高度 ...
- 24.Node.js Stream(流)
转自:http://www.runoob.com/nodejs/nodejs-stream.html Stream 是一个抽象接口,Node 中有很多对象实现了这个接口.例如,对http 服务器发起请 ...
- jQuery post 传递 iframe
//使用POST链接iframe function doOpenPostIfrm(url, args, iframe) { //创建一个隐藏表单 var _form = $("<for ...
- Spring源码分析专题 —— 阅读指引
阅读源码的意义 更深入理解框架原理,印象更深刻 学习优秀的编程风格.编程技巧.设计思想 解决实际问题,如修复框架中的bug,或是参考框架源码,结合实际业务需求编写一个独有的框架 阅读源码的方法 首先是 ...
- selenium模块用法详解
selenium用法详解 selenium主要是用来做自动化测试,支持多种浏览器,爬虫中主要用来解决JavaScript渲染问题. 模拟浏览器进行网页加载,当requests,urllib无法正常获取 ...
- Object.prototype.toString.call(value)
使用Object.prototype上的原生toString()方法判断数据类型,使用方法如下: Object.prototype.toString.call(value) 1.判断基本类型: Obj ...
- 有关 Lambda && linq练习 有待整理
1. 查询Student表中的所有记录的Sname.Ssex和Class列.(select sname,ssex,class from student) Students.Select(s=> ...
- 对象的序列化与反序列化---IO学习笔记(四)
对象的序列化,反序列化 对象的序列化: 就是将Object转换成byte序列 对象的反序列化: 将byte序列转换成Object 序列化流.反序列化流 序列化流(ObjectOutputStream) ...