hdu 4006 The kth great number 优先级队列

来源:互联网 发布:java程序员分级 编辑:程序博客网 时间:2024/05/16 11:21
 #include<iostream>
using namespace std;
#include<queue>
struct node
{
 int num;
 friend bool operator < (node a,node b)
 {
  return a.num>b.num;
 }
} a[100005];
int main()
{
 int n,k;
 int x;
 char cha;
 priority_queue<node> ms;
 while(cin>>n>>k)
 {
  int cout=0;
  while(!ms.empty())
  ms.pop();
  while(n--)
  {
   getchar();
   scanf("%c",&cha);
   if(cha=='I')
   {
    scanf("%d",&x);
    cout++;
    a[cout].num=x;
    ms.push(a[cout]);
    if(cout>k)
    ms.pop();
   }
   else
   printf("%d\n",(ms.top()).num);
  }
 }
 return 0;
}
    
    
原创粉丝点击