hdu4268 multiset應用 貪心
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
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
/**
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;
}
相關文章
- 貪心
- UVA 11020 Efficient Solutions+multiset的應用
- 反悔貪心
- Supermarket(貪心)
- 貪心例題
- 貪心+搜尋
- HDU 5821 Ball(貪心)
- 貪心模式記錄模式
- 反悔貪心雜題
- 貪心演算法演算法
- 貪心、構造合集
- 貪心-刪數問題
- 貪心-*活動選擇
- 24/03/20 貪心(一)
- HDU 6047 Maximum Sequence (貪心)
- HDU 5813 Elegant Construction (貪心)Struct
- 漲薪【貪心】【快速冪】
- Leetcode 貪心:差值調整LeetCode
- Least Cost Bracket Sequence(貪心)ASTRacket
- 刪數問題(貪心)
- 「貪心」做題記錄
- [反悔貪心] Add One 2
- 貪心 做題筆記筆記
- 7.5 - 貪心篇完結
- 貪心演算法Dijkstra演算法
- 牛客 tokitsukaze and Soldier 貪心
- 說說你對貪心演算法、回溯演算法的理解?應用場景?演算法
- 學一下貪心演算法-學一下貪心演算法演算法
- 貪心演算法(貪婪演算法,greedy algorithm)演算法Go
- 牛牛偶像養成記(貪心)
- 貪心(入門簡單題)
- HDU 6299-Balanced Sequence(貪心)
- 【貪心】POJ 3617:Best Cow Line
- Moving Tables(貪心演算法)演算法
- hdu--4435--charge-station+貪心
- 淺談貪心與動歸
- 9-貪心演算法演算法
- [貪心]最大線段重疊
- 牛客 切長條(貪心)