HDU 4006 The kth great number【优先队列】
题意:输入n行,k,如果一行以I开头,那么插入x,如果以Q开头,则输出第k大的数
用优先队列来做,将队列的大小维护在k这么大,然后每次取队首元素就可以了
另外这个维护队列只有k个元素的时候需要注意一下,先将输入的数都插入之后再将多余的数弹出去,这样才能保证留在队列里面的数是前k大的数
另外想到set里面的数是从小到大排列好了的,每次取第k个元素,但是超时了= =
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int INF = 0x7fffffff; int main(){ int n,m,i,j,k,ans;
char ch;
int x;
while(scanf("%d %d",&n,&k)!=EOF){ priority_queue<int,vector<int>,greater<int> >pq; while(n--){
cin>>ch;
if(ch=='I'){
cin>>x;
pq.push(x);
if(pq.size()>k) pq.pop();
} else if(ch=='Q'){
int y=pq.top();
printf("%d\n",y);
}
}
}
return ;
}
HDU 4006 The kth great number【优先队列】的更多相关文章
- hdu 4006 The kth great number (优先队列)
/********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...
- HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- hdu 4006 The kth great number(优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...
- HDU 4006 The kth great number (优先队列)
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
- HDU - 4006 The kth great number multiset应用(找第k大值)
The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming ...
- HDU 4006 The kth great number(multiset(或者)优先队列)
题目 询问第K大的数 //这是我最初的想法,用multiset,AC了——好吧,也许是数据弱也有可能 //multiset运用——不去重,边插入边排序 //iterator的运用,插入的时候,如果是相 ...
- hdu 4006 The kth great number
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...
- HDU 4006 The kth great number AVL解
提供动态更新数据.第实时QK大量的值什么? 使用AVL统计数据结构做,比较先进的数据结构的内容. 不知道给出的数据为准值是否有反复.下面的程序是因为我能够处理重复数据出现的情况下,. 了repeat的 ...
- hdoj 4006 The kth great number【优先队列】
The kth great number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Oth ...
随机推荐
- HTML5程序设计--SVG
SVG(Scalable Vector Graphics):可缩放矢量图形,一种二维图形表示语言. 借助SVG,我们可以实现很多同Canvas API类型的绘制操作,但在Canvas元素上绘制文本的时 ...
- String Reduction
问题出自这里 问题描述: Given a string consisting of a,b and c's, we can perform the following operation: Take ...
- Pots of gold game:看谁拿的钱多
问题描述: Pots of gold game: Two players A & B. There are pots of gold arranged in a line, each cont ...
- jquey ajax 无刷新提交form
http://bbs.csdn.net/topics/380237868 $.ajax({ type: "POST", url:ajaxCallUrl, data:$('#your ...
- iOS搜索栏
百度云连接:http://pan.baidu.com/s/1pJLzDFX
- poj 3317 Stake Your Claim 极大极小搜索
思路:为了方便,当c1>c2时将0变为1,1变为0. 空格最多有10个,每个空格有3个状态,如果不状态压缩,会TLE的.所以最多有3^10种情况 代码如下: #include<iostre ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 水题
A. Pasha and Stick Pasha has a wooden stick of some positive integer length n. He wants to perform ...
- java理论基础学习二
JAVA开发工具 文本编辑器 UltraEdit EditPlus notepad++ 集成开发环境 IDE Integrated Development Enviroment JBuilder h ...
- GetWindowText和GetDlgItemText的区别
二者使用方法相同,入口点不一样. 举例: CString str; /* if (GetDlgItem(IDC_Number1)->GetWindowText(str),str==" ...
- 可任意自定义的 UITableViewCell
可任意自定义的 UITableViewCell UITableView的强大更多程度上来自于可以任意自定义UITableViewCell单元格.通常,UITableView中的Cell是动态的,在使用 ...