HDU_5249(百度之星D题)
来源:互联网 发布:300451创业软件股吧 编辑:程序博客网 时间:2024/05/18 00:01
因为之前没写过平衡树的题,所以很自然地只会用set来写。。。然后,很蠢地想直接找set容器中间位置的那个值,结果iterator没有重载+唉。。。翻了一下AC的代码(果然有跟我一样用set来写的),然后发现是两个set容器解决了这个问题。。。其实很容易想到,一个set容器放前一半的数,一个set容器放后一半的数,就行了。。。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <cstdlib>#include <set>#include <queue>#define FOR(i,x,y) for(int i = x;i < y;i ++)#define IFOR(i,x,y) for(int i = x;i > y;i --)using namespace std;int n;int main(){ //freopen("test.in","r",stdin); int tCase = 0; while(~scanf("%d",&n)){ printf("Case #%d:\n",++tCase); int num; queue <int> s; set <int> p,q; char str[10]; while(n--){ getchar(); scanf("%s",str); if(str[0] == 'q'){ printf("%d\n",*(q.begin())); } else if(str[0] == 'i'){ scanf("%d",&num); s.push(num); if(q.empty() || num < *(q.begin())){ p.insert(num); } else q.insert(num); } else{ int v = s.front(); s.pop(); if(p.find(v) != p.end()){ p.erase(v); } else q.erase(v); } while(p.size() > q.size()){ set <int> :: iterator it = p.end(); it--; int v = *it; p.erase(it); q.insert(v); } while(q.size() > p.size()+1){ set <int> :: iterator it = q.begin(); int v = *it; p.insert(v); q.erase(it); } } } return 0;}
0 0
- HDU_5249(百度之星D题)
- 2012百度之星初赛:D题
- 2016 百度之星 D题
- 2016百度之星资格赛 D题
- 2016百度之星资格赛D题
- 百度之星2016 资格赛D题
- 百度之星-Problem D
- 百度之星之D:共同狂欢
- 百度之星资格赛——D题
- 2012百度之星[D:共同狂欢]
- 百度之星——Problem D
- 2016"百度之星" - 资格赛 Problem D
- 百度之星2016资格赛 D
- 2016"百度之星" - 资格赛 Problem D
- 2016-百度之星-资格赛-Problem D
- 2016百度之星——D
- 2016"百度之星" - 资格赛(Astar Round1) Problem D 简单题
- [2012百度之星资格赛]D:共同狂欢
- andriod工程源代码下载方法
- hdu 1022 Train Problem I (栈的应用)
- 深入理解java多线程中的join()
- 关于如何修改weblogic用户密码的问题
- ps的路径使用
- HDU_5249(百度之星D题)
- 搭建OpenWrt开发环境(包括编译过程)
- 产生冠军set容器
- C++ 求两日期间相隔天数
- [Emacs学习笔记]保存文件和相关操作
- 初学Java—心得体会
- SQL Server 开发指南---Transact-SQL 编程
- 位操作
- 图片上传之fileupload