当前位置:网站首页>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();
}
}
边栏推荐
- Monotonic stack -503 Next bigger Element II
- Convert video to GIF
- Noip 2002 popularity group selection number
- Mortgage Calculator
- AcWing 788. 逆序对的数量
- 我們有個共同的名字,XX工
- LeetCode 324. 摆动排序 II
- How to deal with the core task delay caused by insufficient data warehouse resources
- Deeply understand the underlying data structure of MySQL index
- 22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
猜你喜欢
树形DP AcWing 285. 没有上司的舞会
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
On a un nom en commun, maître XX.
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
Phpstudy 80 port occupied W10 system
AcWing 788. 逆序对的数量
Deep parsing (picture and text) JVM garbage collector (II)
Find the combination number acwing 885 Find the combination number I
樹形DP AcWing 285. 沒有上司的舞會
随机推荐
Memory search acwing 901 skiing
Binary to decimal, decimal to binary
XPath实现XML文档的查询
求组合数 AcWing 886. 求组合数 II
First Servlet
即时通讯IM,是时代进步的逆流?看看JNPF怎么说
AcWing 788. 逆序对的数量
file_ put_ contents
Arbre DP acwing 285. Un bal sans patron.
樹形DP AcWing 285. 沒有上司的舞會
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
How to use Jupiter notebook
Character pyramid
On a un nom en commun, maître XX.
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
[rust note] 10 operator overloading
Methods of using arrays as function parameters in shell
[rust notes] 12 closure
Use of sort command in shell
Summary of methods for counting the number of file lines in shell scripts