Giant pit very subject, it was not even really sample would go to him too, and really pit, look at this question tentatively, anyway, very strange greedy, but not with the pair, because we can not guarantee that all larger than the giant pit
#include<iostream> #include<cstdio> #include<set> #include<algorithm> using namespace std; const int MAX=100000*2+100; struct rectangular { int h,w,bel; }Rect[MAX]; multiset<int>MulSet; multiset<int>::iterator iter; bool cmp1(rectangular a,rectangular b) { if(a.h!=b.h) returnAH < BH; the else IF (AW =! BW) return AW < BW; the else return a.bel> b.bel; // guaranteed after a block to Alice, Bob can cover a block has occurred } int main () { int CAS, I, n-, ANS; CIN >> CAS; the while (cas-- ) { Scanf ( " % D " , & n-); for (I = 0 ; I <n-; I ++ ) { Scanf ( " % % D D " , & Rect [I] .h, &Rect[i].w); Rect[i].bel=1; } for(i=n;i<2*n;i++) { scanf("%d%d",&Rect[i].h,&Rect[i].w); Rect[i].bel=2; } MulSet.clear(); ans=0; sort(Rect,Rect+2*n,cmp1); for(i=0;i<2*n;i++) { if(Rect[i].bel==. 1 ) { IF (! ) MulSet.empty () { ITER = MulSet.begin (); IF (Rect [I] .W> = (* ITER)) { ANS ++ ; ITER = MulSet.upper_bound (Rect [I ] .W); // key is larger than Rect [i] .w first iter--; // ensure delete less Rect [i] .w MulSet the largest element MulSet.erase (ITER); } } } the else { MulSet.insert(Rect[i].w); } } printf("%d\n",ans); } return 0; }