现在的位置: 首页 > 综合 > 正文

hdu 4006 The kth great number

2018年12月30日 ⁄ 综合 ⁄ 共 434字 ⁄ 字号 评论关闭

简单优先队列

#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;
}

抱歉!评论已关闭.