#include <cstdio> #include <algorithm> #include <cmath> //#define DEBUG #ifdef DEBUG #define D(x) x #else #define D(x) #endif using namespace std; int IN[(1 << 20) + 5]; int OUT[(1 << 20) + 5]; void run(int m, int t) { D(printf("m = %d\n", m);) for(int i = 0; i < m; i++) { if(t % 2 == 1) { OUT[i] = IN[m - i - 1]; } else { OUT[i] = IN[i]; } } } int main() { int n, t; scanf("%d %d", &n, &t); int m = 1 << n; for(int i = 0; i < m; i++) { int temp; scanf("%d", &temp); IN[i] = temp; } run(m, t); for(int i = 0; i < m; i++) { printf("%d ", OUT[i]); } printf("\n"); return 0; }
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 | #include <cstdio> #include <algorithm> #include <cmath> //#define DEBUG #ifdef DEBUG #define D(x) x #else #define D(x) #endif using namespace std; int IN[(1 << 20) + 5]; int OUT[(1 << 20) + 5]; void run(int m, int t) { D(printf("m = %d\n", m);) for(int i = 0; i < m; i++) { if(t % 2 == 1) { OUT[i] = IN[m - i - 1]; } else { OUT[i] = IN[i]; } } } int main() { int n, t; scanf("%d %d", &n, &t); int m = 1 << n; for(int i = 0; i < m; i++) { int temp; scanf("%d", &temp); IN[i] = temp; } run(m, t); for(int i = 0; i < m; i++) { printf("%d ", OUT[i]); } printf("\n"); return 0; } |