求第K大数[STL:nth_element]
来源:互联网 发布:如何彻底卸载软件 编辑:程序博客网 时间:2024/06/08 06:00
输入n,k,求第k大
5 25 4 1 3 1
结果:4
#include<cstdio>#include<cmath>#include<cstring>#include<set>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>using namespace std;#define ll long long#define INF 0x7FFFFFFF#define INT_MIN -(1<<31)#define eps 10^(-6)#define Q_CIN ios::sync_with_stdio(false)#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define REV( i , n ) for ( int i = n - 1 ; i >= 0 ; -- i )#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define FOV( i , a , b ) for ( int i = a ; i >= b ; -- i )#define CLR( a , x ) memset ( a , x , sizeof (a) )#define RE freopen("in.txt","r",stdin)#define WE freopen("out.txt","w",stdout)#define NMAX 10002#define min(a,b) ((a)>(b)?(b):(a))int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int arr[5000100];int main(){ int n,k; RE; while(~scanf("%d%d",&n,&k)) { REP(i,n) arr[i] = read(); nth_element(arr,arr+(n-k),arr+n); printf("%d\n",arr[n-k]); } return 0;}
0 0
- 求第K大数[STL:nth_element]
- 使用STL求第K大数
- 求第k大数
- 求第k大数
- 求第k大数
- 求第k大数
- [HDU3292] 求第K大数
- HDU 6040 Hints of sd0061 找第K大数 (nth_element函数)
- 分治算法:线性时间选择第k大小的数字 && STL函数:nth_element()
- 随机伪快排法 求第k大数
- 求数组中第K大数
- N个数,求第K大数
- 求数组的第k大数
- BFPRT算法求第k大数
- 求序列第K大数 POJ2104
- HDU 4006 求第k大数 treap
- N个数,求第K大数
- 快速排序与求第k大数
- Median of Two Sorted Arrays
- eclipse中的.project 和 .classpath文件的具体作用
- 数据结构实验之栈:行编辑器(栈的应用)
- Redis 实践之安装运行
- c#窗口的各种使用
- 求第K大数[STL:nth_element]
- NYOJ 题目26 孪生素数问题
- 社会中的自我
- 从用户态的open到内核驱动实现流程
- 邻接表存储有向图并计算出入度
- 常用的增删改查函数
- 数据和输入输出
- Linux NAND FLASH驱动代码分析
- C++ 二分查找的递归与非递归实现