zoukankan      html  css  js  c++  java
  • HDOJ 4006 The kth great number(优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006

    题意很简单,求第k大的数。用优先队列,输入的时候,队首元素是最小的,每输入一个元素,队列掺毒是否大于 K,若大于k,删除队首元素,这样 队首元素永远是第k大的数。

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main()
    {
    int n,m,i,a;
    char s;
    while(~scanf("%d%d",&n,&m))
    {
    priority_queue<int, vector<int>, greater<int> > q;
    for(i=0;i<n;i++)
    {
    scanf(" %c",&s);
    if(s=='I')
    {
    scanf("%d",&a);
    q.push(a);
    if(q.size()>m)
    q.pop();
    }
    else if(s=='Q')
    printf("%d\n",q.top());
    }
    }
    return 0;
    }
  • 相关阅读:
    01
    商城管理系统
    10
    09
    08
    07(3)
    07(2)
    07
    06
    jsp第一次作业
  • 原文地址:https://www.cnblogs.com/pony1993/p/2598771.html
Copyright © 2011-2022 走看看