import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; public class tas { private static int skipWhitespace(final InputStream in) throws IOException { int val = -1; while ((val = in.read()) != -1) { if (!Character.isWhitespace((char) val)) break; } return val; } private static int readInt(final InputStream in) { final StringBuilder b = new StringBuilder(); try { int val = skipWhitespace(in); b.append((char) val); while ((val = in.read()) != -1) { if (Character.isWhitespace((char) val)) break; b.append((char) val); } return Integer.parseInt(b.toString()); } catch (final IOException e) { throw new RuntimeException(e); } } public static void run(final InputStream in, PrintStream out) { int n = readInt(in); int t = readInt(in); int z = (int) Math.pow(2, n); int[] a = new int[z]; for (int i = 0; i < z; i++) { a[i] = readInt(in); } if (t % 2 == 0) { for (int i = 0; i < z; i++) { System.out.print(a[i] + " "); } } else { for (int i = z - 1; i >= 0; i--) { System.out.print(a[i] + " "); } } } /** * @param args */ public static void main(String[] args) { run(System.in, System.out); } }
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 | import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; public class tas { private static int skipWhitespace(final InputStream in) throws IOException { int val = -1; while ((val = in.read()) != -1) { if (!Character.isWhitespace((char) val)) break; } return val; } private static int readInt(final InputStream in) { final StringBuilder b = new StringBuilder(); try { int val = skipWhitespace(in); b.append((char) val); while ((val = in.read()) != -1) { if (Character.isWhitespace((char) val)) break; b.append((char) val); } return Integer.parseInt(b.toString()); } catch (final IOException e) { throw new RuntimeException(e); } } public static void run(final InputStream in, PrintStream out) { int n = readInt(in); int t = readInt(in); int z = (int) Math.pow(2, n); int[] a = new int[z]; for (int i = 0; i < z; i++) { a[i] = readInt(in); } if (t % 2 == 0) { for (int i = 0; i < z; i++) { System.out.print(a[i] + " "); } } else { for (int i = z - 1; i >= 0; i--) { System.out.print(a[i] + " "); } } } /** * @param args */ public static void main(String[] args) { run(System.in, System.out); } } |