70

あこがれの秋

11小时前
import java.util.Scanner;

public class Main {
public static Scanner sc = new Scanner(System.in);

private static int[] array = new int[100010];
private static int[] temp = new int[100010];

public static void main(String[] args) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) array[i] = sc.nextInt();

merge_sort(array, 0, n - 1);

for (int i = 0; i < n; i++)  System.out.print(array[i] + " ");;
}

private static void merge_sort(int[] array, int l, int r) {
if (l >= r) return;

int mid = (l + r) >> 1;
merge_sort(array, l, mid);
merge_sort(array, mid + 1, r);

int i = l, j = mid + 1, z = l;
while (i <= mid && j <= r) {
if (array[i] < array[j]) {
temp[z++] = array[i++];
} else {
temp[z++] = array[j++];
}
}
while (i <= mid) temp[z++] = array[i++];
while (j <= r) temp[z++] = array[j++];

System.arraycopy(temp, l, array, l, r - l + 1);
}
}



11小时前
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
int k = sc.nextInt();
int[] array = new int[n];
for (int i = 0; i < n; i++) array[i] = sc.nextInt();

quick_sort(array, 0, n - 1);

System.out.println(array[k - 1]);;
}

private static void quick_sort(int[] array, int l, int r) {
if (l >= r) return;

int x = array[l + r >> 1], i = l - 1, j = r + 1;
while (i < j) {
while (array[++i] < x);
while (array[--j] > x);

if (i < j) sweep(array, i, j);
}
quick_sort(array, l, j);
quick_sort(array, j + 1, r);
}

private static void sweep(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}



11小时前
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int[] array = new int[sc.nextInt()];
for (int i = 0; i < n; i++) array[i] = sc.nextInt();

quit_sort(array, 0, n - 1);

for (int i = 0; i < n; i++)  System.out.print(array[i] + " ");;
}

private static void quit_sort(int[] array, int l, int r) {
if (l >= r) return;

int x = array[l];
int i = l - 1, j = r + 1;

while (i < j) {
while (array[++i] < x);
while (array[--j] > x);

if (i < j) sweep(array, i, j);
}
quit_sort(array, l, j);
quit_sort(array, j + 1, r);
}

private static void sweep(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}



16天前

16天前