码迷,mamicode.com
首页 > 其他好文 > 详细

STL 堆

时间:2016-11-16 19:39:19      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:while   push   turn   long   ++   get   nbsp   etc   const   

洛谷P3378 【模板】堆

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N=1e6+5;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<0||c>9){if(c==-)f=-1;c=getchar();}
    while(c>=0&&c<=9){x=x*10+c-0;c=getchar();}
    return x*f;
}
int n,op,x;
int a[N],len=0;
inline bool cmp(int a,int b){return a>b;}
int main(){
    n=read();
    for(int i=1;i<=n;i++){
        op=read();
        if(op==1){
            a[len++]=read();
            push_heap(a,a+len,cmp);
        }else if(op==2) printf("%d\n",a[0]);
        else pop_heap(a,a+len,cmp),len--;
    }
}

 

STL 堆

标签:while   push   turn   long   ++   get   nbsp   etc   const   

原文地址:http://www.cnblogs.com/candy99/p/6071074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!