hdu4268 multiset应用 贪心
来源:互联网 发布:硬盘恢复数据价格 编辑:程序博客网 时间:2024/06/05 19:44
http://acm.hdu.edu.cn/showproblem.php?pid=4268
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.
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.
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
221 23 42 34 532 35 76 84 12 53 4
Sample Output
12
/**hdu 4268 multiset应用题目大意:一牌,如果他的长和宽都分别不小于另一张,那么这张牌就可以覆盖另一张,问在A的牌中,有多少 可以覆盖B的牌(一张牌只能覆盖一张,并且长宽已给出,并不一定长度大的的就是长)解题思路:这道题的数据如果小一点,完全可以用二分图来做。对AB的牌进行排序长递增,然后枚举A的牌,把所有B 的牌大于A的长的加入multiset里,利用lower_bound()找出宽最小的一个,然后删除该元素。复杂度O(n*logn)*/#include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <set>using namespace std;const int maxn=100005;int n;multiset <int> s;struct note{ int x,y; bool operator < (const note &other)const { return x<other.x; }}a[maxn],b[maxn];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a[i].x,&a[i].y); } for(int i=0;i<n;i++) { scanf("%d%d",&b[i].x,&b[i].y); } sort(a,a+n); sort(b,b+n); s.clear(); int k=0,ans=0; for(int i=0;i<n;i++) { while(a[i].x>=b[k].x&&k<n) { s.insert(b[k].y); k++; } if(s.empty())continue; multiset<int>::iterator it=s.lower_bound(a[i].y); if(it==s.end()||a[i].y<*it)it--; if(*it<=a[i].y) { ans++; s.erase(it); } } printf("%d\n",ans); } return 0;}
0 0
- hdu4268 multiset应用 贪心
- ACM 贪心 STL multiset 二分查找 hdu4268
- hdu4268贪心
- hdu4268 Alice and Bob,multiset
- hdu4268(贪心+set)
- hdu4268 Alice and Bob(二维贪心的固定思想 STL的multiset的二分查找函数实现)
- [STL][multiset] hdu4268 Alice and Bob
- hdu4268(贪心+set容器)
- HDU4268 Alice and Bob 【贪心】
- hdu4268
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
- hdu4268 排序贪心Alice and Bob
- hdu4268 Alice and Bob(贪心)
- HDU4268 Alice and Bob【贪心+SET】
- multiset应用
- HDU4864Task 贪心multiset使用
- UVALive 7416 贪心 multiset
- POJ 3038 贪心(multiset)
- Android Metro风格的Launcher开发系列第一篇
- ubuntu12.04命令安装MySQL
- 获取数据库表及表结构
- 窗口的注册与创建
- TimesTen 数据库monitor 使用分析
- hdu4268 multiset应用 贪心
- UVA 11324 The Largest Clique
- 有趣的累加求和实现
- hdu 1533 流流流
- git入门及常用命令
- Android RelativeLayout相对布局
- 一次因为数据问题引起的reduce被卡住streaming作业问题排查
- iOS——创建圆形头像
- 中国佛学66句震撼世界的禅语(转贴)