Alice and Bob

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2869    Accepted Submission(s): 926
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
 

题意:一个物品有两个參数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 【贪心】的更多相关文章

  1. HDU4268 Alice and Bob(贪心+multiset)

    Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...

  2. Alice and Bob(贪心HDU 4268)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  3. HDU 4268 Alice and Bob 贪心STL O(nlogn)

    B - Alice and Bob Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  4. HDU 4268 Alice and Bob(贪心+Multiset的应用)

     题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...

  5. hdu 4268 Alice and Bob(multiset|段树)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  7. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  8. Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)

    Alice and Bob Time Limit: 1000ms   Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...

  9. sdutoj 2608 Alice and Bob

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...

随机推荐

  1. HDU 3487(Play with Chain-Splay)[template:Splay]

    Play with Chain Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. 兔子--ps中的基本工具总结(ps cs5)

    矩形选框工具 椭圆选框工具 单行选框工具 单列选框工具 移动工具 套索工具柜 多边形套索工具 磁性套索工具 魔棒工具 高速选择工具 裁剪工具 切片工具 切片选择工具 吸管工具 颜色取样器工具 标尺工具 ...

  3. SDUT--Pots(二维BFS)

    Pots Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 You are given two pots, having the ...

  4. 在Qt Creator的项目中添加头文件和库

    在Qt Creator中的工程中,工程通过.pro文件管理. 额外需要连接的连接库unix:LIBS += -L your_lib_path -lyour_libwin32:LIBS += your_ ...

  5. golang md5

    package main import ( "crypto/md5" "encoding/hex" "fmt" "io" ...

  6. python路径找类并获取静态字段

    Python通过路径找类并获取其中大写的静态字段 settings.py class Foo: DEBUG = True TEST = True xx.py import importlib path ...

  7. BZOJ2157: 旅游(LCT)

    Description Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间 ...

  8. startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

    startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI ...

  9. css中的!important作用

    css中的!important作用 一.总结 1.!important:是hack, 2.!important作用:让浏览器首选执行这个语句,当对同一个对象设置了多个同类型的属性的时候,首选执行这一个 ...

  10. 【iOS开发系列】颜色渐变

    记录: //Transparent Gradient Layer - (void) insertTransparentGradient { UIColor *colorOne = [UIColor c ...