洛谷 https://www.luogu.org/problem/show?pid=T575
来源:互联网 发布:传奇世界h5辅助软件 编辑:程序博客网 时间:2024/04/20 23:19
输入格式:
第一行一个正整数N
第二行N个整数Ai
若Ai>0,则在把Ai扔到堆里
若Ai=0,则输出一行一个数,分别表示当前堆里的最大值。(保证堆非空)
若Ai<0,则把-Ai从堆里丢出去(保证堆中存在Ai)(若有多个只丢一个)
输出格式:
行数为Ai=0的个数,如输入描述。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<set>using namespace std;priority_queue<int>q;int n;multiset<int>s;multiset<int>::iterator it;int main(){ scanf("%d",&n); int x; for(int i=1;i<=n;i++) { scanf("%d",&x); if(x>0) { q.push(x); continue; } else if(x<0) { s.insert(-x); continue; } else if(x==0) { it=s.find(q.top()); if(it==s.end()) { printf("%d\n",q.top()); continue; } else { do { s.erase(q.top()); q.pop(); it=s.find(q.top()); } while(it!=s.end()); printf("%d\n",q.top()); } } }}
%%%sys
虽然是堆排……但是显然set的可重集合更简单……
3 0
- 洛谷 https://www.luogu.org/problem/show?pid=T575
- 洛谷 https://www.luogu.org/problem/show?pid=T574
- 洛谷P1011 车站(题目来源:https://www.luogu.org/problem/show?pid=1011)
- 洛谷 P3378 【模板】堆(https://www.luogu.org/problem/show?pid=3378)
- 洛谷 P3383 【模板】线性筛素数(https://www.luogu.org/problem/show?pid=3383)
- 洛谷P1025 数的划分(题目来源https://www.luogu.org/problem/show?pid=1025)
- Dragons https://www.bnuoj.com/v3/problem_show.php?pid=26407
- https://www.virtualbox.org/wiki/Linux_Downloads
- ZK 网址 https://www.zkoss.org/
- https://www.tensorflow.org/get_started/mnist/pros
- https://www.kernel.org/doc/Documentation/PCI/
- problem.php?pid=513
- luogu 1001 A+B problem
- http://www.lihuasoft.net/news/show.php?id=4395
- Problem D. Fashion Show
- https://www.usenix.org/legacy/event/sec11/tech/slides/enck.pdf
- 测试网站兼容性:http://browsershots.org/ 和https://www.browserstack.com/
- 无法连接到“https://www.nuget.org/api/v2/”中指定的源
- 169. Majority Element
- HDU-3486-Interviewe
- android M权限适配,简单工具类
- java--内存分配
- Nova Conductor服务
- 洛谷 https://www.luogu.org/problem/show?pid=T575
- 欢迎使用CSDN-markdown编辑器
- 装饰模式
- 用振动台校准传感器的一个教训
- 怎么在图片加载成功之前用另一个图片代替
- Gradle常见配置总结
- 嵌入式系统1
- 在vs2008中运行这个就闪退了,,还出不来结果
- 开源的容器虚拟化平台Docker学习笔记,个人私藏分享,不谢!