poj 3481 Double Queue STL中map的运用
2015-01-14 22:46
435 查看
题意:
维护一个集合,操作有1:加入一个元素,2:删除最大元素,3:删除最小元素。
分析:
map本质是个容器,且具有第一个关键字有序的性质,所以用它来水水就好啦~
代码:
维护一个集合,操作有1:加入一个元素,2:删除最大元素,3:删除最小元素。
分析:
map本质是个容器,且具有第一个关键字有序的性质,所以用它来水水就好啦~
代码:
//poj 3481 //sep9 #include <iostream> #include <map> using namespace std; map<int,int> mymap; map<int,int>::iterator iter; int main() { int x,sum=0; while(scanf("%d",&x)==1&&x){ if(x==1){ int a,b; scanf("%d%d",&a,&b); mymap[b]=a; ++sum; }else if(x==2){ if(sum==0) printf("0\n"); else{ iter=mymap.end(); --iter; printf("%d\n",iter->second); mymap.erase(iter); --sum; } }else if(x==3){ if(sum==0) printf("0\n"); else{ iter=mymap.begin(); printf("%d\n",iter->second); mymap.erase(iter); --sum; } } } return 0; }
相关文章推荐
- POJ-3481 Double Queue STL练手
- poj 3481 Double Queue splay
- POJ 3481 Double Queue Treap
- POJ 3481 & HDU 1908 Double Queue (map运用)
- Double Queue POJ 3481
- PKU3481(Double Queue)STL-map
- POJ 3481 Double Queue splay
- Double Queue - POJ 3481 - 树堆Treap的数组实现
- [poj 3481]Double Queue[set || map][STL]
- POJ 3481 & HDU 1908 Double Queue (map运用)
- Double Queue POJ - 3481
- poj 3481 Double Queue(Size Balance Tree)
- POJ 3481 Double Queue
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- 【String+Map版】从poj 1002——487-3279的STL做法和若干陷阱来分析MAP
- STL有限队列的灵活运用+IO优化+区间最大最小——POJ Sliding Window
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)