HDU5340.MZL's simple problem
来源:互联网 发布:镜像变换矩阵是什么 编辑:程序博客网 时间:2024/06/16 09:40
首先,题目的要求是能查找最大值,删除最小值,插入值
那么我们可以用优先队列或者multiset按从小到大排序,删除的时候只要把第一个元素删除,
最大值的话优先队列比较麻烦一点,需要不停地维护其最大值,而multiset只需要返回它end()的前面一位就行了,(前提非空)
下面见两种写法
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;const int INF=0x3f3f3f3f;/*优先队列void solve(int n){ priority_queue<int,vector<int>,greater<int> >Q; int a,b; int minv=-INF; for(int i=1;i<=n;i++){ scanf("%d",&a); if(a==1){ scanf("%d",&b); Q.push(b); minv=max(minv,b); } if(a==2){ if(!Q.empty()){ int tmp=Q.top(); Q.pop(); if(tmp==minv) minv=-INF; } } if(a==3){ if(!Q.empty()) printf("%d\n",minv); else printf("0\n"); } }}int main(){ int n; while(scanf("%d",&n)!=EOF){ solve(n); } return 0;}*//*multisetvoid solve(int n){ multiset<int> fifth; int a,b; for(int i=1;i<=n;i++){ scanf("%d",&a); if(a==1){ scanf("%d",&b); fifth.insert(b); } if(a==2){ if(!fifth.empty()){ fifth.erase(fifth.begin()); } } if(a==3){ if(!fifth.empty()){ printf("%d\n",*(--fifth.end())); } else printf("0\n"); } }}int main(){ int n; while(scanf("%d",&n)!=EOF){ solve(n); } return 0;}*/
0 0
- HDU5340.MZL's simple problem
- HDU 5349 MZL's simple problem
- HDOJ 5349 MZL's simple problem 【set】
- HDU 5349 MZL's simple problem
- hdu 5349 MZL's simple problem (set)
- HDU 5349 MZL's simple problem
- 【multiset】hdu 5349 MZL's simple problem
- hdu 5349 MZL's simple problem
- [水题] hdu 5349 MZL's simple problem
- [HDU 5349] MZL's simple problem 神题
- hdu 5349 MZL's simple problem
- Contest 5 1007 MZL's simple problem
- hdu 5349 MZL's simple problem
- 其他-HDOJ-5349-MZL's simple problem
- hdu-5349-MZL's simple problem
- Hdu 5349 MZL's simple problem (水题)
- 2015 Multi-University Training Contest 5 - MZL's simple problem
- HDU 5347 多校赛1007 MZL's simple problem
- C#网络编程《二》
- OpenGL着色器语言4.14-4.1.7(浮点型变量,向量,矩阵,不透明类型(采样器))
- ZOJ 题目2734 Exchange Cards(DFS 去重OR 母函数)
- uwsgi启动并与django关联
- 树的广度优先遍历与深度优先遍历算法
- HDU5340.MZL's simple problem
- css入门——声明属性
- 博弈之——SG模板(hdu1848&&hdu1536)
- 黑马程序员——Java 面向对象_继承
- 1.1 kettle 抽取文本文件
- DPDK 收发包处理流程(二)(网卡初始化)
- 命令模式
- Objective-C关于含有多个参数的类对象方法的定义及实现
- Nginx+Keepalived实现Web服务器负载均衡