Alice and Bob both have N Rectangles and ask Alice how many rectangles can cover Bob at most. Each rectangle can be used only once, and the width and height cannot be rotated. --> Greedy, the first thought of strategy is: sort the rectangle in descending order of width and height, and then Alice uses the widest to cover Bob's widest, the result is WA. Now we find that the direction is reversed! The greedy strategy should be from small to large, so that every rectangle of Alice can exert its maximum value, that is, take one of them: width, access from small to large, each access one, find all the satisfied heights from small to large in height, and cover the largest one as far as possible (multiset has the search function upper_bound (x), and returns the first iterator greater than x ). It's a good taste to use pair and multiset for the first time ~~ [Cpp] # include <cstdio> # include <vector> # include <set> # include <algorithm> using namespace std; typedef pair <int, int> pii; const int maxn = 100000 + 10; int main () {int T, N, I, j, h, w; scanf ("% d", & T ); while (T --) {scanf ("% d", & N); vector <pii> A, B; for (I = 0; I <N; I ++) {scanf ("% d", & h, & w);. push_back (make_pair (h, w) ;}for (I = 0; I <N; I ++) {scanf ("% d", & h, & w); B. push_back (make _ Pair (h, w);} sort (. begin (),. end (); sort (B. begin (), B. end (); int cnt = 0; multiset <int> s; s. clear (); for (I = 0, j = 0; I <N; I ++) {while (j <N & A [I]. first> = B [j]. first) s. insert (B [j ++]. second); if (! S. empty () www.2cto.com {multiset <int>: iterator p = s. upper_bound (A [I]. second); if (p! = S. begin () {s. erase (-- p); cnt ++ ;}} printf ("% d \ n", cnt) ;}return 0 ;}