uva 11020 Efficient Solutions

题意:给你n个人,有两个属性x、y,如果不存在另外一个人x2,y2满足 x2<=x,y2<y 或者 x2<x,y2<=y,那么就称这个人是有优势的,每次给你一个人得信息,问你当前有优势的人的人数是多少?

思路:刘汝佳训练指南P228 mutiset+lower_bound+upper_bound

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