UVA - 11020 - Efficient Solutions (multiset实现BST)
来源:互联网 发布:数据库中的decode 编辑:程序博客网 时间:2024/06/07 06:46
Efficient Solutions
题目传送:Efficient Solutions
AC代码:
#include <map>#include <set>#include <cmath>#include <deque>#include <queue>#include <stack>#include <cstdio>#include <cctype>#include <string>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define INF 0x7fffffffusing namespace std;int n;struct node { int x, y; node(int _x, int _y) : x(_x), y(_y) { } node() { } bool operator < (const node& a) const { return x < a.x || (x == a.x && y < a.y); }};multiset<node> s;multiset<node>::iterator it;int main() { int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas ++) { if(cas > 1) printf("\n"); printf("Case #%d:\n", cas); scanf("%d", &n); s.clear(); for(int i = 0; i < n; i ++) { int x, y; scanf("%d %d", &x, &y); node t = node(x, y); it = s.lower_bound(t);//返回第一个大于等于t的元素的位置 if(it == s.begin() || (--it)->y > y) { s.insert(t); it = s.upper_bound(t);//返回第一个比t大的元素的位置 // while(it != s.end() && it->y >= y) s.erase(it ++); for(; it != s.end() && it->y >= y; ) { s.erase(it ++);//只能通过这种方法删除set里的连续的一段,如果it++写外面就会出错,因为it在之前所指向的值已经被删除了 //迭代器it是通过++运算指向后一个元素的,所以只能通过在删除的时候一起++才行 } } printf("%d\n", s.size()); } } return 0;}
0 0
- UVA 11020 Efficient Solutions(BST multiset实现)
- UVA - 11020 - Efficient Solutions (multiset实现BST)
- UVA 11020 Efficient Solutions (用multiset实现BST)
- UVA 11020 Efficient Solutions(multiset,数据结构)
- UVA 11020(Efficient Solutions-multiset的lower_bound)
- UVA 11020 Efficient Solutions+multiset的应用
- Uva-11020-Efficient Solutions
- UVA 11020 Efficient Solutions
- UVA 11020 - Efficient Solutions
- UVA 11020 Efficient Solutions(STL,set)
- Efficient Solutions+BST(排序二叉树)
- UVA 11020 - Efficient Solutions(set)
- uva 11020 - Efficient Solutions(STL)
- UVA 11020 Efficient Solutions set
- UVA Efficient Solutions (优势人群)——multiset、排序二叉树
- Uva 11020 Efficient Solutions (set的应用)
- UVA 11020 Efficient Solutions(C++STL应用)
- Uva 11120 Efficient Solutions
- SPI相关理论知识总结
- CSS基础-17CSS盒子模型-外边距合并
- Android设计模式系列-单例模式
- 9.谓词(Predicate)
- hdu1299
- UVA - 11020 - Efficient Solutions (multiset实现BST)
- POI-----POI操作Excel-5、公式
- SVM理解
- 【Unity3D游戏开发】GameObject.Find()、Transform.Find查找隐藏对象 (十)
- markdown快速入门
- hdu4549 斐波那契数列(乘法递推) + 欧拉定理 (快速幂,模幂)
- 《Sublime Text 2搭建Java开发环境》
- HDOJ 4883 TIANKENG’s restaurant(贪心)
- codeforces290E