import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class tas { public static void main(String[] args) throws IOException { InputReader inputReader = new InputReader(System.in); int n = inputReader.readInt(); int t = inputReader.readInt(); int len = 1 << n; int[] ar = new int[len]; for (int i = 0; i < len; i++) ar[i] = inputReader.readInt(); if ((t & 1) == 1) for (int i = 0; i < len; i++) System.out.print(ar[len - i - 1] + " "); else for (int i = 0; i < len; i++) System.out.print(ar[i] + " "); System.out.println(); } private static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer("", " "); InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 100*1000); } String nextString() throws IOException { if (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine(), " "); return tokenizer.nextToken(); } int readInt() throws IOException { return Integer.parseInt(nextString()); } } }
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 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class tas { public static void main(String[] args) throws IOException { InputReader inputReader = new InputReader(System.in); int n = inputReader.readInt(); int t = inputReader.readInt(); int len = 1 << n; int[] ar = new int[len]; for (int i = 0; i < len; i++) ar[i] = inputReader.readInt(); if ((t & 1) == 1) for (int i = 0; i < len; i++) System.out.print(ar[len - i - 1] + " "); else for (int i = 0; i < len; i++) System.out.print(ar[i] + " "); System.out.println(); } private static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer("", " "); InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 100*1000); } String nextString() throws IOException { if (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine(), " "); return tokenizer.nextToken(); } int readInt() throws IOException { return Integer.parseInt(nextString()); } } } |