UVA 11020 Efficient Solutions+multiset的应用
来源:互联网 发布:上海市软件测评中心 编辑:程序博客网 时间:2024/05/19 16:35
题目链接:点击进入
首先来讲,很容易看到我们其实只要维护优势人群的集合;如果加入一个新的人,我们首先看一下优势人群中是否有人会让这个人失去优势,如果没有,则将这个人插入集合中,但要注意到这个人的插入可能会让其它的人失去优势。所以要求这个集合要能支持快速查询和修改操作;而multiset恰好能能满足这个需要。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<set>using namespace std;struct Point{ int a,b; ///Set中的元素按x进行排序 bool operator <(const Point& rhs) const { return a<rhs.a||(a==rhs.a&&b<rhs.b); }};multiset<Point>S;multiset<Point>::iterator it;int main(){ //freopen("in.txt","r",stdin); int T; scanf("%d",&T); for(int Case=1;Case<=T;Case++) { if(Case!=1) printf("\n"); printf("Case #%d:\n",Case); int n,a,b; scanf("%d",&n); S.clear(); while(n--) { scanf("%d%d",&a,&b); Point P=(Point){a,b}; it = S.lower_bound(P); ///在红黑树中查找第一个小于P的元素 if(it==S.begin()|| (--it)->b >=b ) ///如果P也具有优势 { S.insert(P); it = S.upper_bound(P); ///it以后的元素都会被影响 while(it!=S.end()&&it->b >=b) S.erase(it++); ///删除掉失去优势的人 } printf("%d\n",S.size()); } } return 0;}
1 0
- UVA 11020 Efficient Solutions+multiset的应用
- UVA 11020(Efficient Solutions-multiset的lower_bound)
- UVA 11020 Efficient Solutions(multiset,数据结构)
- UVA 11020 Efficient Solutions(BST multiset实现)
- UVA - 11020 - Efficient Solutions (multiset实现BST)
- UVA 11020 Efficient Solutions (用multiset实现BST)
- Uva 11020 Efficient Solutions (set的应用)
- UVA 11020 Efficient Solutions(C++STL应用)
- Uva-11020-Efficient Solutions
- UVA 11020 Efficient Solutions
- UVA 11020 - Efficient Solutions
- UVA 11020 - Efficient Solutions(set)
- uva 11020 - Efficient Solutions(STL)
- UVA 11020 Efficient Solutions set
- uva11020 Efficient Solutions(STL multiset的应用+二分查找函数)
- UVA 11020 Efficient Solutions(STL,set)
- Uva 11120 Efficient Solutions
- UVA Efficient Solutions (优势人群)——multiset、排序二叉树
- 南邮 OJ 1912 E.V.O.L
- Eclipse安装Freemarker Editor插件
- 亚信数据:运营商数据挖掘-从架构到应用
- Android 基础:SharePreferences知识总结和在“登录”界面的范例实现
- JavaScript之document.cookie使用总结
- UVA 11020 Efficient Solutions+multiset的应用
- fork创建进程
- linux 日常命令
- socket select模型编程
- rest实战
- svn linux命令
- 南邮 OJ 1913 闹钟
- JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
- hdoj 5033 凸包