Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4268
The question is: ask you the maximum number of Bob cards that Alice can cover. Card cannot be flipped
Idea: First we sort the cards by height regardless of the type, and then we judge the card type in sequence. If it is Bob's card, we put the width of his card into Multiset, if Alice's card is used, find the one with the largest width in Multiset and delete it.
# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <algorithm> # include <set> using namespace STD; const int maxn = 200005; struct node {int H, W, ID;} node [maxn]; bool CMP (node T1, node T2) {If (t1.h! = T2.h) return t1.h <t2.h; If (t1.w! = T2.w) return t1.w <t2.w; return t1.id <t2.id;} Multiset <int> S; Multiset <int>: iterator ite; int main () {int N, I, t; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= 2 * n; I ++) {scanf ("% d", & node [I]. h, & node [I]. w); node [I]. id = (I <= N);} Sort (node + 1, node + 2 * n + 1, CMP); S. clear (); int sum = 0; for (I = 1; I <= 2 * n; I ++) {If (node [I]. id = 0) s. insert (node [I]. w); else {If (S. empty () | node [I]. W <* (S. begin () continue; ite = S. upper_bound (node [I]. w); // find ite --; sum ++; S. erase (ITE); // Delete} printf ("% d \ n", sum);} return 0 ;}
HDU 4268 Alice and Bob (Multiset)