import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created by tzmarz on 2016-11-21. */ public class tas { private int N; private int[] input; private int kIter; void readInput() { N = 1 << nextInt(); input = new int[N]; kIter = nextInt(); for (int i = 0; i < N; i++) { input[i] = nextInt(); } } public String solve() { StringBuilder sb = new StringBuilder(); if (kIter % 2 == 0) { for (int i = 0; i < N; i++) { sb.append(input[i]); sb.append(" "); } } else { for (int i = 0; i < N; i++) { sb.append(input[N - i - 1]); sb.append(" "); } } return sb.toString(); } public static void main(String[] args) { tas tas = new tas(); tas.readInput(); System.out.println(tas.solve()); } /********** reader ***********/ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); private String next() { try { while (!st.hasMoreTokens()) { String str; str = br.readLine(); if (str == null) return null; st = new StringTokenizer(str); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } private int nextInt() { return Integer.parseInt(next()); } }
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 69 70 71 72 73 74 75 76 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created by tzmarz on 2016-11-21. */ public class tas { private int N; private int[] input; private int kIter; void readInput() { N = 1 << nextInt(); input = new int[N]; kIter = nextInt(); for (int i = 0; i < N; i++) { input[i] = nextInt(); } } public String solve() { StringBuilder sb = new StringBuilder(); if (kIter % 2 == 0) { for (int i = 0; i < N; i++) { sb.append(input[i]); sb.append(" "); } } else { for (int i = 0; i < N; i++) { sb.append(input[N - i - 1]); sb.append(" "); } } return sb.toString(); } public static void main(String[] args) { tas tas = new tas(); tas.readInput(); System.out.println(tas.solve()); } /********** reader ***********/ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); private String next() { try { while (!st.hasMoreTokens()) { String str; str = br.readLine(); if (str == null) return null; st = new StringTokenizer(str); } } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } private int nextInt() { return Integer.parseInt(next()); } } |