hdu 4268

set的利用;

 1 #include<cstdio>
 2 #include<set>
 3 #include<algorithm>
 4 #define maxn 100009
 5 using namespace std;
 6 
 7 struct node
 8 {
 9     int w,h;
10     bool operator <(const node& t)const
11     {
12         if(w==t.w)return h<t.h;
13         return w<t.w;
14     }
15 }a[maxn],b[maxn];
16 
17 multiset<int>s;
18 multiset<int>::iterator it;
19 int main()
20 {
21     int n,t;
22     scanf("%d",&t);
23     while(t--)
24     {
25         scanf("%d",&n);
26         s.clear();
27         int sum=0;
28         for(int i=0;i<n;i++)scanf("%d%d",&a[i].w,&a[i].h);
29         for(int i=0;i<n;i++)scanf("%d%d",&b[i].w,&b[i].h);
30         sort(a,a+n);
31         sort(b,b+n);
32         int j=0;
33         for(int i=0;i<n;i++)
34         {
35             while(j<n&&b[j].w<=a[i].w)
36             {
37                 s.insert(b[j].h);
38                 j++;
39             }
40             if(!s.size())continue;
41             it=s.upper_bound(a[i].h);
42             if(it!=s.begin())
43             {
44                 sum++;
45                 s.erase(--it);
46             }
47         }
48         printf("%d
",sum);
49     }
50     return 0;
51 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3420077.html