http://acm.hdu.edu.cn/showproblem.php?pid=4268
Problem Descriptionalice and Bob ' s game never ends. Today, they introduce a new game. In this game, both of them has N different rectangular cards respectively. Alice wants to use he 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 are not smaller than B. As the best programmer, you is asked to compute the maximal number of Bob's cards that Alice can cover.
Please pay attention this each card can is used only once and the cards cannot be rotated.
Inputthe first line of the input is a number T (T <=) which means the number of test cases.
For each case, the first line was a number N which means the number of cards that Alice and Bob had respectively. Each of the following n (n <= 100,000) lines contains-integers h (H <= 1,000,000,000) and W (w <= 1,000,000,0 XX) which means the height and width of Alice's card, then the following N lines means that of Bob ' s.
Outputfor each test case, output a answer using one line which contains just one number.
Sample Input
Sample Output
12
/**hdu 4268 multiset Application title: A card, if his length and width are not less than another, then this card can cover another, ask in a card, how many can cover B card (a card can only cover one, and the length of the width has been given, and is not necessarily long) solution The idea: If the data of this problem is small, it can be done with a binary map. The AB cards are sorted in a long increments, then enumerate A's cards, put all B's cards larger than A's long join Multiset, use Lower_bound () to find the smallest one, and then delete the element. Complexity 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;}
hdu4268 multiset Application Greed