hdu 4006 The kth great number

简单优先队列




#include<iostream>
#include<stdio.h>
#include<functional>
#include<queue>
#include<vector>
using namespace std;
int main()
{
		
	int i,n,k,a;
	char ch;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		getchar();
		priority_queue<int, vector<int>, greater<int> > q;//格式有点坑爹,都用空格隔开,不然编译错误
		for(i=1;i<=n;i++)
		{
			scanf("%c",&ch);
			if(ch=='I')
			{
				scanf("%d",&a);
				
				if(q.size()<k||q.empty())
					q.push(a);
				else 
				{
					if(a>q.top())
					{
						q.pop();
					    q.push(a);
					}
				}
			}
			else
			{
				printf("%d\n",q.top());
			}
			getchar();
		}
	}
	return 0;
}


你可能感兴趣的:(hdu 4006 The kth great number)