zoukankan      html  css  js  c++  java
  • 【luogu 3378】【模板】堆

    题目描述

    如题,初始小根堆为空,我们需要支持以下3种操作:

    操作1: 1 x 表示将x插入到堆中

    操作2: 2 输出该小根堆内的最小数

    操作3: 3 删除该小根堆内的最小数

    输入输出格式

    输入格式:

    第一行包含一个整数N,表示操作的个数

    接下来N行,每行包含1个或2个正整数,表示三种操作,格式如下:

    操作1: 1 x

    操作2: 2

    操作3: 3

    输出格式:

    包含若干行正整数,每行依次对应一个操作2的结果。

    输入输出样例

    输入样例#1:
    5
    1 2
    1 5
    2
    3
    2
    输出样例#1:
    2
    5

    说明

    时空限制:1000ms,128M

    数据规模:

    对于30%的数据:N<=15

    对于70%的数据:N<=10000

    对于100%的数据:N<=1000000(注意是6个0。。。不过不要害怕,经过编者实测,堆是可以AC的)

    样例说明:

    故输出为2、5

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<queue>
     6 using namespace std;
     7 int read(){
     8     int x=0,f=1;char ch=getchar();
     9     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    10     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    11     return x*f;
    12 }
    13 priority_queue<int,vector<int>,greater<int> > q;
    14 int Q;
    15 int main(){
    16     Q=read();
    17     for(int i=1;i<=Q;i++){
    18         int a=read();
    19         if(a==1){
    20             int b=read();
    21             q.push(b);
    22         }
    23         else if(a==2){
    24             printf("%d
    ",q.top());
    25         }
    26         else{
    27             q.pop();
    28         }
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    c盘瘦身、windows解除上网限速、贴膜注意事项
    windows7导入k8s用户证书
    ubuntu报错解决和注意事项
    ubuntu默认root密码问题,第一次使用ubuntu需要设置root密码
    java程序员修炼之道
    选择器代码
    css的使用技巧资料
    移动开发的相关资料
    使用phantomjs生成网站快照
    PHP Simple HTML DOM Parser Manual-php解析DOM
  • 原文地址:https://www.cnblogs.com/Emine/p/7639653.html
Copyright © 2011-2022 走看看