当前位置:网站首页>acwing 786. Number k
acwing 786. Number k
2022-06-13 09:24:00 【Age worry】
786. The first k Number
subject :
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N],m;
void sort1(){
sort(a,a+n);
}
void sort2(int l,int r){
if(l>=r) return;
int mid=(l+r)>>1;
//cout<<mid<<endl;
sort2(l,mid);
sort2(mid+1,r);
int t[N],k=0;
int i=l,j=mid+1;
for(;i<=mid && j<=r;){
if(a[i]<=a[j]) t[k++]=a[i++];
else t[k++]=a[j++];
}
while(i<=mid) t[k++]=a[i++];
while(j<=r) t[k++]=a[j++];
for(int i=0;i<k;i++){
a[l+i]=t[i];
}
}
void sort3(int l,int r){
if(l>=r) return ;
int i=l-1,j=r+1,x=(l+r)>>1;
while(i<j){
do i++;while(a[i]<a[x]);
do j--;while(a[j]>a[x]);
if(i<j) swap(a[i],a[j]);
}
sort3(l,i);sort3(i+1,r);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort1();
//sort2(0,n-1);
//sort3(0,n-1);
printf("%d ",a[m-1]);
return 0;
}
边栏推荐
- HAProxy + Keepalived实现MySQL的高可用负载均衡
- Jenkins集成Ldap,Ldap配置错误导致jenkins用户登录失败问题解决
- LeetCode 5270. 网格中的最小路径代价(动态规划)
- Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
- I set up a blog
- LeetCode 343. integer partition
- 20211006 linear transformation
- ROS2之OpenCV人脸识别foxy~galactic~humble
- Delete soft link
- LeetCode 322. Change
猜你喜欢
(bfs) acwing 844. Labyrinth
Simulink variant model and variant subsystem usage
Exporting MySQL data table documents using Navicat
20211020 academician all drive system
C language: five custom types
Jenkins接入Openldap用户认证
Redis fuzzy query batch deletion
C/s model and P2P model
C language: preprocessing in program environment
Tutorial (5.0) 04 Fortint cloud services and scripts * fortiedr * Fortinet network security expert NSE 5
随机推荐
Figure introduction to database neo4j
JUC 原子累加器
How Simulink adds modules to the library browser
JUC atomic reference and ABA problem
JUC原子数组
20220606 Young's inequality for Matrices
Yolov5 face learning notes
Online debugging tool Arthas advanced
(dp+ memory) acwing 901 skiing
C language: file operation
Online debugging tool Arthas Foundation
批量读取文件夹下的全部语音文件
@Value does not take effect and extend/implement other classes cannot inject beans manually
线上调试工具Arthas基础
JUC atomic accumulator
BGP Federation +community
Solov2 nanny level tutorial (including environment configuration, training your own data set, code logic analysis, etc...) Updating ing
SpEL表达式 简单使用
C language: callback function
JUC Unsafe