HDU - 4006 The kth great number (set&数据结构)

原创 2016年06月01日 14:29:05
HDU - 4006
Time Limit:                                                        1000MS                          Memory Limit: 65768KB   64bit IO Format:                            %I64d & %I64u                       

Status

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). 
         
               

Source

The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
//题意:
给你一个n,m,表示有n组输入,如果字母是I,输入一个数,否则表示询问第m大的数字是什么
//思路:
直接用multiset进行存放,当存放的数的个数大于m时就删除最后的那个,否则输出最后的那个数即可
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<set>
#define INF 0x3f3f3f3f
#define N 1000010
using namespace std;
char s[2];
struct zz
{
	int x;
	friend bool operator < (zz a,zz b)
	{
		return a.x>b.x;
	}
}p;
multiset<zz>st;
multiset<zz>::iterator f;
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		st.clear();
		for(int i=0;i<n;i++)
		{
			scanf("%s",s);
			if(s[0]=='I')
			{
				scanf("%d",&p.x);
				st.insert(p);
				f=st.end();
				f--;
				if(st.size()>m)
					st.erase(f);
			}
			else
			{
				f=st.end();
				f--;
				printf("%d\n",*f);		
			}	
		}
	}
	return 0;
}

hduoj~The kth great number~优先队列

The kth great number Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65768/65768K (Java/Oth...
  • lin14543
  • lin14543
  • 2015-07-29 10:25:05
  • 500

HDOJ The kth great number (优先队列)

The kth great number Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65768/65768K (Java/Othe...
  • helloiamclh
  • helloiamclh
  • 2015-07-28 21:15:35
  • 428

hdu 4006 The kth great number

Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming c...
  • u011721440
  • u011721440
  • 2013-10-31 11:10:06
  • 503

HDU 4006 The kth great number

点击打开链接 The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768...
  • Dinivity123
  • Dinivity123
  • 2013-04-29 16:20:04
  • 855

HDU 4006:The kth great number

问题描述 一共有n次操作,插入或者查询第k大的数 解题思路 优先队列,刚开始的时候很蠢的把所有的数都存到了优先队列了,TLE了一遍之后发现只需保持优先队列里有k个数就好了。 代码 #include ...
  • liangyuppp
  • liangyuppp
  • 2017-08-24 15:30:41
  • 47

HDU 4006 The kth great number

这题的关键在于理解:要求第K大数,那么我们只保留前K个大数,并且按降序排列。这也就是说每加入一个数就找到这个数的位置。 然后将大于K个元素之外的数删除。 利用优先级队列就可以很好的做到这一点。 ...
  • Lulipeng_cpp
  • Lulipeng_cpp
  • 2012-06-01 17:11:13
  • 1295

HDU 4006 - The kth great number

传送门HDU 4006 - The kth great number 本来想找
  • u014247806
  • u014247806
  • 2014-05-31 22:53:32
  • 660

HDU 4006 The kth great number

#include #include #include #include #include #include #include using namespace std; int main() { ...
  • u014221090
  • u014221090
  • 2014-08-19 09:37:29
  • 176

HDU2665 Kth number(主席树入门)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2665 主席树呢,就是可持久化线段树,非常神奇。我在B站看了qsc大神的视频之后就大概懂意思了,先做个入...
  • xtttgo
  • xtttgo
  • 2016-05-20 13:31:52
  • 551
收藏助手
不良信息举报
您举报文章:HDU - 4006 The kth great number (set&数据结构)
举报原因:
原因补充:

(最多只允许输入30个字)