NEU OJ 1644 Median I

优先级队列

#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;
}
时间: 2024-10-12 02:22:09

NEU OJ 1644 Median I的相关文章

山东省赛题 NEU OJ 1444 线段树双标记

http://acm.neu.edu.cn/hustoj/problem.php?id=1444 OJ问题论坛发帖http://t.cn/zjBp4jd FAQ http://t.cn/zjHKbmN Linux问题看http://t.cn/aWnP1n 1444: Devour Magic 时间限制: 1 Sec  内存限制: 256 MB 提交: 129  解决: 21 [提交][状态][讨论版] 题目描述 In Warcraft III, Destroyer is a large flyi

LeetCode OJ 4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1,

【LeetCode OJ】Median of Two Sorted Arrays

题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/ 题目:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 解题思路:将两个有序数

九度oj 1004 Median 2011年浙江大学计算机及软件工程研究生机试真题

题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:14162 解决:3887 题目描述: Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 1

NEU OJ 1651 Great number

循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostream> #include<cstring> using namespace std; const long long MOD = 1e9+7; long long mod1(char *a1,int b) { long long a[5000] = {0}; long long c[500

NEU OJ 1649 GMZ’s Pretty Number

先来一次线性素数筛,把1到10000000的素数都筛选出来,然后暴力跑一遍所有可能的值,打个表,查询的时候o(1)效率出解. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<cstring> using namespace std; const long N = 10000000; long

Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 =&gt; gcd(x*y,x+y)=1

/** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生选拔赛题 题意:给定两个数的和以及他们的最小公倍数,求这两个数. 思路: x+y=A lcm(x,y)=B => x*y/gcd(x,y)=B 要把这两个公式联立,那么必须消掉gcd: 设:d = gcd(x,y), x = kx*d, y = ky*d; kx与ky互质: x+y=A => d(

LeetCode OJ - Median of Two Sorted Arrays

题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 解题思路: 将原问题转变成一个寻找第k小数的问题(假设两个原序列升序排列),这样中位数实际上是第(m+n)/2小的数.所以只要解决了第k小数的问题,原问题也得以解决

【LeetCode OJ 004】Median of Two Sorted Arrays

题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/ 题目:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 解题思路:将两个有序数