HDU 4268

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #include <set>
 6 using namespace std;
 7 
 8 const int N=100010;
 9 struct Node{
10     int x,y,type;
11     bool operator<(const Node &b) const {
12         if(x!=b.x) return x<b.x;
13         if(y!=b.y) return y<b.y;
14         return type>b.type;
15     }
16 };
17 
18 typedef multiset<int> SET;
19 typedef multiset<int>::iterator IT;
20 
21 
22 Node a[N<<1];
23 SET S;
24 const int Inf=0x80000000;
25 int T,n;
26 
27 
28 int main() {
29     scanf("%d",&T);
30     while(T--) {
31         scanf("%d",&n);
32         for(int i=0;i<2*n;i++) scanf("%d%d",&a[i].x,&a[i].y);
33         for(int i=0;i<n;i++) a[i].type=0;
34         for(int i=n;i<n<<1;i++) a[i].type=1;
35         sort(a,a+2*n);
36         S.clear();
37         int ans=0;
38         for(int i=0;i<2*n;i++) {
39             if(a[i].type==1) S.insert(a[i].y);
40             else {
41                 if(!S.empty()){
42                     if(*S.begin()<=a[i].y){
43                         IT it=S.upper_bound(a[i].y);
44                         it--;
45                         ans++;
46                         S.erase(it);
47                     }
48                 }
49             }
50         }
51         printf("%d\n",ans);
52     }
53     return 0;
54 }
原文地址:https://www.cnblogs.com/hxsyl/p/2677249.html