zoukankan      html  css  js  c++  java
  • hdu 4006 第K大的数(优先队列)

    N次操作 I是插入一个数 Q是输出第K大的数

    Sample Input
    8 3 //n k
    I 1
    I 2
    I 3
    Q
    I 5
    Q
    I 4
    Q

    Sample Output
    1
    2
    3

     1 # include <iostream>
     2 # include <cstdio>
     3 # include <cstring>
     4 # include <algorithm>
     5 # include <string>
     6 # include <cmath>
     7 # include <queue>
     8 # include <list>
     9 # define LL long long
    10 using namespace std ;
    11 
    12 struct ss
    13 {
    14     friend bool operator<(const ss a,const ss b)
    15     {
    16         if(a.v>b.v)
    17             return 1;
    18         else
    19             return 0;
    20     }
    21     int v;
    22 };
    23 
    24 int main()
    25 {
    26     //freopen("in.txt","r",stdin) ;
    27     int n , k ;
    28     char s[10];
    29     while(scanf("%d %d" , &n , &k) != EOF)
    30     {
    31         priority_queue<ss> q ;
    32         ss t;
    33         while(n--)
    34         {
    35             scanf("%s",s);
    36             if(s[0]=='I')
    37             {
    38                 int a;
    39                 scanf("%d",&a);
    40                 t.v=a;
    41                 q.push(t);
    42                 if(q.size()>k)
    43                 {
    44                     q.pop();
    45                 }
    46             }
    47             else
    48             {
    49                 printf("%d
    ",q.top());
    50             }
    51         }
    52     }
    53 
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    道路和航线
    Sorting It All Out
    Sightseeing Cows(0/1分数规划+Spfa判负环)
    【模板】缩点
    间谍网络
    Tarjan算法专练
    数论知识点总结
    博客迁移到博客园
    第一届CCPC河南省赛
    find程序实现
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/4836389.html
Copyright © 2011-2022 走看看