首页 > 其他 > 详细

NEU OJ 1644 Median I

时间:2015-08-12 21:29:32      阅读:283      评论:0      收藏:0      [点我收藏+]

优先级队列

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int n;
int main()
{
    while(~scanf("%d",&n))
    {
        int tot=0;
        priority_queue<int>Q;
        while(n--)
        {
            int x;
            scanf("%d",&x);
            if(x==1)
            {
                int u;
                scanf("%d",&u);
                tot++;
                Q.push(u);
            }
            else if(x==2)
            {
                if(tot==0) printf("-1\n");
                else
                {
                    int r=tot-(tot/2+1);
                    while(r--) Q.pop();
                    int h=Q.top();
                    printf("%d\n",h);
                    tot=(tot/2+1);
                }
            }
        }
    }
    return 0;
}

 

NEU OJ 1644 Median I

原文:http://www.cnblogs.com/zufezzt/p/4725339.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!