P1168 中位数
来源:互联网 发布:windows安装清理工具 编辑:程序博客网 时间:2024/05/24 16:14
https://www.luogu.org/problem/show?pid=1168#sub
用上c++的stl中的优先队列,小根堆用负值来存,构成对顶堆,就变成了一道水题。
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<cmath>#include<algorithm>#include<queue>using namespace std;int n;priority_queue <int> q1;//大根堆 priority_queue <int> q2;//小根堆 int main(){ scanf("%d",&n); int x; for(int i=1;i<=n;i++) { scanf("%d",&x); q1.push(x); while(q1.size()>q2.size()+1) { x=q1.top();q1.pop();x=-x; q2.push(x); } while(q1.size()<q2.size()+1) { x=q2.top();q2.pop();x=-x; q1.push(x); } if(i%2) { x=q1.top(); printf("%d\n",x); } } return 0;}
阅读全文
1 1
- P1168 中位数
- |洛谷|堆|P1168 中位数
- 洛谷 P1168 中位数
- 洛谷 P1168 中位数
- 洛谷P1168 中位数
- 洛谷P1168 中位数
- 洛谷P1168 中位数(堆)
- 二分树状数组-洛谷P1168 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- 中位数
- CSU 1671 经营小卖部 (完全背包 DP)
- js验证是否为数字的总结
- ios面试题,各大企业常见的ios面试题之五
- 【数据库系统概念】第11章 索引与散列 知识总结
- 训练日记-4
- P1168 中位数
- hdu-6070 _Dirt Ratio (二分答案+线段树维护)
- 【BFS】皇宫VS迷宫
- 设计模式C++实现(5)——原型模式、模板方法模式
- MySQL全文本搜索Hello
- spark笔记
- AbstractString
- Servlet 生命周期、工作原理
- Oracle增删改查训练