import java.util.Arrays; import java.util.Scanner; public class tas { public static void main(String[] args) { Scanner in = new Scanner( System.in ); int n = in.nextInt(); long t = in.nextLong(); if (n < 1 || n > 20 || t < 1 || t > 1000000000) { System.exit(0); } int length = 2; for (int i = n; i > 1; i--) { length *= 2; } long[] cards = new long[length]; for (int i = 0; i < cards.length; i++) { cards[i] = in.nextLong(); } for (long i = t; i > 0; i--) { cards = sort(cards); System.out.println("chuj"); } for (int i = 0; i < cards.length; i++) { System.out.print(cards[i] + " "); } } public static long[] sort(long[] array){ int middle = (array.length)/2; long[] a = Arrays.copyOfRange(array,0 ,middle); long[] b = Arrays.copyOfRange(array, middle, array.length); for(int i = 0; i < a.length / 2; i++) { long temp = a[i]; a[i] = a[a.length - i - 1]; a[a.length - i - 1] = temp; } for(int i = 0; i < b.length / 2; i++) { long temp = b[i]; b[i] = b[b.length - i - 1]; b[b.length - i - 1] = temp; } int aLen = a.length; int bLen = b.length; long[] c = new long[aLen+bLen]; System.arraycopy(b, 0, c, 0, bLen); System.arraycopy(a, 0, c, bLen, aLen); for (int i = 0; i < c.length; i++) { System.out.println(c[i]); } return c; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | import java.util.Arrays; import java.util.Scanner; public class tas { public static void main(String[] args) { Scanner in = new Scanner( System.in ); int n = in.nextInt(); long t = in.nextLong(); if (n < 1 || n > 20 || t < 1 || t > 1000000000) { System.exit(0); } int length = 2; for (int i = n; i > 1; i--) { length *= 2; } long[] cards = new long[length]; for (int i = 0; i < cards.length; i++) { cards[i] = in.nextLong(); } for (long i = t; i > 0; i--) { cards = sort(cards); System.out.println("chuj"); } for (int i = 0; i < cards.length; i++) { System.out.print(cards[i] + " "); } } public static long[] sort(long[] array){ int middle = (array.length)/2; long[] a = Arrays.copyOfRange(array,0 ,middle); long[] b = Arrays.copyOfRange(array, middle, array.length); for(int i = 0; i < a.length / 2; i++) { long temp = a[i]; a[i] = a[a.length - i - 1]; a[a.length - i - 1] = temp; } for(int i = 0; i < b.length / 2; i++) { long temp = b[i]; b[i] = b[b.length - i - 1]; b[b.length - i - 1] = temp; } int aLen = a.length; int bLen = b.length; long[] c = new long[aLen+bLen]; System.arraycopy(b, 0, c, 0, bLen); System.arraycopy(a, 0, c, bLen, aLen); for (int i = 0; i < c.length; i++) { System.out.println(c[i]); } return c; } } |