uva 11020

用可重集;

首先按照x排好序,然后只要找到下界,插入,然后把y坐标大于它的都删掉就行;

 1 #include<cstdio>
 2 #include<set>
 3 using namespace std;
 4 
 5 struct node
 6 {
 7     int a,b;
 8     bool operator<(const node &t)const
 9     {
10         if(a==t.a)return b<t.b;
11         return a<t.a;
12     }
13 };
14 
15 multiset<node>s;
16 multiset<node>::iterator it;
17 
18 int main()
19 {
20     int t,n,ca=1;
21     node p;
22     scanf("%d",&t);
23     while(t--)
24     {
25         s.clear();
26         printf("Case #%d:
",ca++);
27         scanf("%d",&n);
28         while(n--)
29         {
30             scanf("%d%d",&p.a,&p.b);
31             it=s.lower_bound(p);
32             if(it==s.begin()||(--it)->b >p.b)
33             {
34                 s.insert(p);
35                 it=s.upper_bound(p);
36                 while(it!=s.end()&&it->b>=p.b)s.erase(it++);
37             }
38             printf("%d
",s.size());
39         }
40         if(t>0)puts("");
41     }
42     return 0;
43 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3400505.html