hdu-5349-MZL's simple problem

Description
A simple problem
Problem Description
You have a multiple set,and now there are three kinds of operations:
1 x : add number x to set
2 : delete the minimum number (if the set is empty now,then ignore it)
3 : query the maximum number (if the set is empty now,the answer is 0)

Input
The first line contains a number N ( N106 ),representing the number of operations.
Next N line ,each line contains one or two numbers,describe one operation.
The number in this set is not greater than 109 .

Output
For each operation 3,output a line representing the answer.

Sample Input

6
1 2
1 3
3
1 3
1 4
3

Sample Output

3
4
有三种操作,1,输入个x,将他加入一个集合,2,找出最小的值并删除,3,找出最大的值并输出。
一拿到题就会发现是裸的优先队列。然后直接模拟过去就好了

#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 500005;
const int inf = 1000000000;
int main()
{
    int n,k,a,Max;
    while(scanf("%d",&n)!=EOF)
    {
        Max=-inf;
        priority_queue<int> q;
        while(n--)
        {
            scanf("%d",&k);
            if(k==1)
            {
                scanf("%d",&a);
                q.push(a);
                Max=Max>a?Max:a;
            }
            else if(k==2)
            {
                if(q.empty())
                    continue;
                q.pop();
                if(q.empty())
                    Max=-inf;
            }
            else if(k==3)
            {
                if(q.empty())
                {
                    printf("0\n");
                    continue;
                }
                printf("%d\n",Max);
            }
        }
    }
    return 0;
}

你可能感兴趣的:(hdu-5349-MZL's simple problem)