hdu 4006

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65768/65768K (Java/Other)
Total Submission(s) : 51   Accepted Submission(s) : 20

Problem Description

Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too much, Xiao Bao is feeling giddy. Now, try to help Xiao Bao.

Input

There are several test cases. For each test case, the first line of input contains two positive integer n, k. Then n lines follow. If Xiao Ming choose to write down a number, there will be an " I" followed by a number that Xiao Ming will write down. If Xiao Ming choose to ask Xiao Bao, there will be a "Q", then you need to output the kth great number.

Output

The output consists of one integer representing the largest number of islands that all lie on one line.

Sample Input

8 3 I 1 I 2 I 3 Q I 5 Q I 4 Q

Sample Output

1 2 3 [hint]Xiao Ming won‘t ask Xiao Bao the kth great number when the number of the written number is smaller than k. (1=<k<=n<=1000000).[/hint]

利用优先队列和set容器很容易解出

#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<set>
using namespace std;
multiset <int> q;
multiset <int>::iterator it;
int main()
{
    int m,n;
    while(~scanf("%d%d",&n,&m))
    {
        q.clear();
        char s[2];
        while(n--)
        {
            int x;
            scanf("%s",&s);

            if(s[0]==‘I‘){
                scanf("%d",&x);
                q.insert(x);
                if(q.size()>m){
                    q.erase(q.begin());
                }
            }
            else{
                    it=q.begin();
                printf("%d\n",*it);
            }
        }
    }
}

  

时间: 2024-10-19 04:10:10

hdu 4006的相关文章

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu

HDU 4006 求第k大数 treap

裸题,瞬秒.. #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include <vector> #include <set> #include <map> #include <queue> using namespace std; #define L(id) tree[id].ch[0] #defin

hdu 4006 The kth great number (优先队列+STB+最小堆)

The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 6637    Accepted Submission(s): 2671 Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a roun

HDU 4006 The kth great number AVL解法

给出动态更新数据,实时问第K个大的数值是什么? 利用AVL数据结构做的一个统计数,比较高级的数据结构内容了. 不知道题目给出的数据值是否有重复,因为我下面的程序是可以处理出现数据重复的情况的. 其中的奥妙是增加了repeat的信息,可以知道出现了当前数组多少次. 主要是知道如何维护这些数据和如何查询,维护数据的函数是pushUp,查询函数是selectKth. 其他就是一般的AVL操作.个人觉得我的AVL写的还算蛮清晰的,有需要的参考一下. #include <stdio.h> inline

hdu 4006 The kth great number (优先队列)

1 /********************************************************** 2 题目: The kth great number(HDU 4006) 3 链接: http://acm.hdu.edu.cn/showproblem.php?pid=4006 4 算法: 优先队列 5 ************************************************************/ 6 #include<cstdio> 7 #

HDU 4006 The kth great number(multiset(或者)优先队列)

题目 询问第K大的数 //这是我最初的想法,用multiset,AC了——好吧,也许是数据弱也有可能 //multiset运用——不去重,边插入边排序 //iterator的运用,插入的时候,如果是相同的数没直接放在相同的现有的数据后面的 #include<cstdio> #include<cstring> #include<algorithm> #include<set> using namespace std; //#define IN freopen(

hdu 4006/AvlTree

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 这道题以前用c语言写的Avltree水过了.. 现在接触了c++重写一遍... 由于没有删除操作故不带垃圾回收,具体如下: 1 #include<cstdio> 2 #include<cstdlib> 3 #include<iostream> 4 #define Max_N 1000100 5 inline int max(int &a, int &b

hdu 4006 The kth great number/SBT

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 这题原先用treap写过的,现在看了sb树..本来想练习一下sbt树重复元素的插入, 搞了半天跟以前写的treap方法完全不一样/(ㄒoㄒ)/~~, 照下面的写法重复的节点被完全插入到树中了,o(╯□╰)o.. 如果重复元素很多,那会浪费太多的空间,不知到有没啥好的方法... 还是再慢慢想想吧,T_T- #include<stdio.h> #include<stdlib.h> #

hdu 4006 The kth great number(优先队列)

The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 6982    Accepted Submission(s): 2837 Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a roun

HDU 4006: The kth great number

The kth great number ///@author Sycamore ///@date 8/8/2017 #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; while (cin >> n >> k) { char ch; int t; multiset<int>s; while (