#include<cstdio> #include<algorithm> using namespace std; int MAX_N = (1<<20) + 1; int main(int args, char* argv[]) { int n, m; int* t = new int[MAX_N]; scanf("%d%d", &n, &m); int size = 1<<n; for(int i = 0; i < size; i++) scanf("%d", t+i); if (m%2==1) { int i = 0, j = size - 1; while(i < j) swap(t[i++], t[j--]); } for(int i = 0; i < size; i++) printf("%d ", t[i]); delete []t; 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 | #include<cstdio> #include<algorithm> using namespace std; int MAX_N = (1<<20) + 1; int main(int args, char* argv[]) { int n, m; int* t = new int[MAX_N]; scanf("%d%d", &n, &m); int size = 1<<n; for(int i = 0; i < size; i++) scanf("%d", t+i); if (m%2==1) { int i = 0, j = size - 1; while(i < j) swap(t[i++], t[j--]); } for(int i = 0; i < size; i++) printf("%d ", t[i]); delete []t; return 0; } |