the kth number第几大数问题
第几大数问题the kth number
Problem description
Find the kth largest element in an unsorted array A . Note that it is the kth largest element in
the sorted order, not the kth distinct element. The range of length of A is N(1≤N≤5,000,000) and the element (integer) in A is no bigger than 10,000,00000.
问题描述在未排序的数组A中找到第k个最大元素。 请注意,它是排序顺序中第k个最大的元素,而不是第k个不同的元素。 A的长度范围是N(1≤N≤5,000,000),A中的元素(整数)不大于10,000,00000。
Input
Line 1: the length of the unsorted array A and the index k.
Line 2: the all elements in array A and split by spaces
Output
Line 1: A single integer that is the kth largest element in an unsorted array A.
Sample Input 1
8 2
1 3 5 7 4 2 6 8
Sample Output 1
7
Sample Input 2
8 2
1 1 2 2 3 3 4 4
Sample Output 2
4
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;const int maxn = 5e6 + 10;int a[maxn];int main() {int n,k; cin >> n >> k;for (int i = 0; i < n; i++) scanf("%d",&a[i]);sort(a, a + n);cout << a[n - k] << endl;return 0;
}
the kth number第几大数问题相关推荐
- poj2104 k-th number 主席树入门讲解
poj2104 k-th number 主席树入门讲解 定义:主席树是一种可持久化的线段树 又叫函数式线段树 刚开始学是不是觉得很蒙逼啊 其实我也是 主席树说简单了 就是 保留你每一步操作完成之后 ...
- 刷题记录(NC14301 K-th Number,7-2 分数的小数形式表示)
NC14301 K-th Number 题目链接 关键点: 1.本题要求求给出一个数组,然后求这个数组的子区间中的第k大的数全部提出来,然后再全部放进一个新的数组里,再去求这个数组的第m大数 2.二分 ...
- NC14301 K-th Number
题目: NC14301 K-th Number ,哈哈,我们今天来看一道有点思维难度的题嘛,这是选自牛客上的一道题,好了,我们一起来看看题意吧: 考虑到直接复制题目,或者截屏的方式不是很方便阅读,我就 ...
- 【做练习】K-th Number(线段树)线段树的原理
1. 题目 描述 You are working for Macrohard company in data structures department. After failing your pre ...
- POJ_2104 K-th Number 【主席树】
一 题面 K-th Number 二 分析 第一个主席树的题,感触蛮多吧,几个关键点就是可持久化数据结构,这里的主席树其实就是保留了之前各个版本的权值线段树,然后利用权值线段树和历史版本可以进行相加减 ...
- K-th Number
题目链接:http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MS Memory Limit: 65536K Total Sub ...
- [CareerCup][Google Interview] Find kth number in a BST
Find kth number in a BST 递归实现,按照左根右的顺序来实现 1 #include <iostream> 2 using namespace std; 3 4 str ...
- POJ 2104 K-th Number 主席树(区间第k大)
题目链接: http://poj.org/problem?id=2104 K-th Number Time Limit: 20000MSMemory Limit: 65536K 问题描述 You ar ...
- hdu 2665 Kth number(划分树模板)
http://acm.hdu.edu.cn/showproblem.php?pid=2665 [ poj 2104 2761 ] 改变一下输入就可以过 http://poj.org/problem? ...
最新文章
- 在C#程序中实现插件架构
- 洛谷 P1207 [USACO1.2]双重回文数 Dual Palindromes
- 一个亿万富翁和一个陌生人的换钱计划
- akka连接是什么_什么是Akka?
- MapReduce算法–了解数据联接第1部分
- php 数组去重且不保留,php数组去重并计数求和如何操作
- linux 关闭rsync服务器,linux下配置rsync服务器和实时同步
- 键盘上每个键作用!!! (史上最全的)
- MySQL 实例空间使用率过高的原因和解决方法
- double几位小数_算法竞赛入门之每日一题:分数化化小数(decimal) C语言
- (转)DevOps,就是开发吃掉运维?
- 服务器为啥要搭建在2012系统,WindowsServer2012R2搭建SFTP服务器以及配置
- 金山毒霸系统清理专家
- 跳步游戏2--返回最小跳步数
- Mysql复制原理以及流程
- 人工智能狂潮_患有社交媒体狂潮? 使用这些工具从一个地方管理所有帐户
- mysql rls_各种类型RLS自适应滤波算法的C++实现
- sourceinsight 查看源码的利器
- java饼图_java 百分比饼图的实现代码
- Pandas学习笔记(二)—— Pandas索引