import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Scanner;
//输入n个数字ai,输出这些数字的第k小的数。最小的数是第0小。
public class Main {
public static void main(String[] args) throws IOException {
StreamTokenizer sc = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
sc.nextToken();
int n = (int) sc.nval;
sc.nextToken();
int k = (int) sc.nval;
// Scanner sc = new Scanner(System.in);
// int n = sc.nextInt();//n个数
// int k = sc.nextInt();//第k小的数
int a[] = new int[n];
for (int i = 0; i < n; i++) {
sc.nextToken();
a[i] = (int) sc.nval;
}
for (int i = 0; i < a.length; i++) {
for (int j = i; j < a.length; j++) {
}
}
//Quick_sort(a, 0, a.length - 1);
//System.out.println(a[k]);o(nlogn)
int i = find(a, 0, a.length - 1, k);
}
public static int find (int[] a,int left, int right, int k)
{ //在数组a的第left到right中寻找第k小的数
int tem=Partition(a,left,right);
if(k==tem)
System.out.println(a[k]);
else if(k-1<tem)//判断下一次划分在哪一区间进行
find(a,left,tem-1,k);
else
find(a,tem+1,right,k);
return 0;
}
public static void Quick_sort(int[] a, int low, int high) {
if (low < high) {
int p = Partition(a, low, high);
Quick_sort(a, low, p - 1);
Quick_sort(a, p + 1, high);
}
}
public static int Partition(int[] a, int low, int high) {
int pivot = a[low];//pivot 支点;中心
while (low < high) {
while (low < high && a[high] >= pivot)
high--;
a[low] = a[high];
while (low < high && a[low] <= pivot) low++;
a[high] = a[low];
}
a[low] = pivot;
return low;//return high
}
}
分类目录:《深入理解强化学习》总目录 马尔可夫过程是一组具有马尔可夫性质的随机变量序列 S 1 , S 2 , ⋯ , S t S_1, S_2, \cdots, S_t S1,S2,⋯,St,其中下一个时刻的状态 S t 1 S_{t1} St1只取决于当前状态 S t S_t St 。我们设状态的历史…