当前位置:网站首页>AcWing 786. Number k
AcWing 786. Number k
2022-07-03 09:01:00 【Sasakihaise_】
【 Quick line up 】 According to the idea of fast platoon , Up to the middle separation point =k
// package AcWing.course;
import java.io.StreamTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
// 7:50. 8:06
static int n, k, ans = 0;
static int[] arr;
static StreamTokenizer st;
static int nextInt() throws Exception {
st.nextToken();
return (int)st.nval;
}
static void quickSort(int l, int r){
if(l > r) return;
int i = l, j = r, pivot = arr[l];
while(i < j){
while(i < j && arr[j] > pivot) j--;
arr[i] = arr[j];
while(i < j && arr[i] <= pivot) i++;
arr[j] = arr[i];
}
arr[i] = pivot;
if(i == k) {
ans = arr[i];
return;
}else if(i > k){
quickSort(l, i - 1);
}else{
quickSort(i + 1, r);
}
}
public static void main(String[] args) throws Exception {
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pw = new PrintWriter(System.out);
n = nextInt();
k = nextInt() - 1;
arr = new int[n];
for(var i = 0; i < n; i++) arr[i] = nextInt();
quickSort(0, n - 1);
pw.println(ans);
pw.flush();
}
}
边栏推荐
- 浅谈企业信息化建设
- Too many open files solution
- Markdown learning
- C language file reading and writing
- [rust notes] 08 enumeration and mode
- XPath实现XML文档的查询
- Using variables in sed command
- 22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
- 数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
- 传统企业数字化转型需要经过哪几个阶段?
猜你喜欢

AcWing 787. 归并排序(模板)

Markdown learning

PHP uses foreach to get a value in a two-dimensional associative array (with instances)

Too many open files solution

低代码前景可期,JNPF灵活易用,用智能定义新型办公模式

First Servlet

求组合数 AcWing 886. 求组合数 II

MySQL three logs

教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
![[concurrent programming] explicit lock and AQS](/img/5f/a80751a68726f53d11133810f454a3.jpg)
[concurrent programming] explicit lock and AQS
随机推荐
高斯消元 AcWing 883. 高斯消元解线性方程组
Find the combination number acwing 885 Find the combination number I
一个优秀速开发框架是什么样的?
On the setting of global variable position in C language
低代码起势,这款信息管理系统开发神器,你值得拥有!
传统企业数字化转型需要经过哪几个阶段?
Gif remove blank frame frame number adjustment
Concurrent programming (VI) ABA problems and solutions under CAS
Using variables in sed command
How to use Jupiter notebook
Servlet的生命周期
Query XML documents with XPath
常见渗透测试靶场
Discussion on enterprise informatization construction
Solution of 300ms delay of mobile phone
AcWing 786. 第k个数
[rust notes] 06 package and module
Using DLV to analyze the high CPU consumption of golang process
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
TP5 multi condition sorting