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

NEU OJ 1644 Median I

时间:2015-08-12 21:32:17      阅读:144      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!