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 ...
随机推荐
- Mobile Web 调试指南(2):远程调试
原文:http://blog.jobbole.com/68606/ 原文出处: 阿伦孟的博客(@allenm ) 第一篇中讲解了如何让手机来请求我们开发电脑上的源码,做到了这步后,我们可以改完代码立即 ...
- iOS block示例
// // block.h // Block // // Created by tqh on 15/4/12. // Copyright (c) 2015年 tqh. All rights reser ...
- Razor视图引擎 语法学习(一)
ASP.NET MVC是一种构建web应用程序的框架,它将一般的MVC(Model-View-Controller)模式应用于ASP.NET框架: ASP.NET约定优于配置:基本分为模型(对实体数据 ...
- NGINX轻松管理10万长连接 --- 基于2GB内存的CentOS 6.5 x86-64
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=190176&id=4234854 一 前言 当管理大量连接时,特别 ...
- JLINK固件丢失或升级固件后提示Clone的解决办法
J-LINK V8固件烧录指导 J-LINK 是使用过程中,如果内部固件意外损坏或丢失,请参考下面操作步骤说明,重新烧录JLINK固件. 安装固件烧录软件 请ATMEL官方网址下载AT91-ISP下载 ...
- 295. Find Median from Data Stream
题目: Median is the middle value in an ordered integer list. If the size of the list is even, there is ...
- 275. H-Index II
题目: Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optim ...
- java Cache框架
Cache框架乱炖 各类开源的缓存解决方案 JBossCache/TreeCacheJBossCache是一个复制的事务处理缓存,它允许你缓存企业级应用数据来更好的改善性能.缓存数据被自动复制,让 ...
- HtmlHelper
HtmlHelper类 public class HtmlHelper<TModel> : HtmlHelper类 因为HtmlHelper<TModel>继承自HtmlHel ...
- JQUERY与JS的区别
JQUERY与JS的区别 <style type="text/css"> #aa { width:200px; height:200px; } </style&g ...