#include <iostream> #include <vector> #include <utility> #include <stdio.h> using namespace std; void force(vector<int>& vv, int start, int end); int main() { int n, t; scanf("%d %d", &n, &t); vector<int> vv(1<<n); for (int i = 0; i < (1<<n); ++i) { int tmp; scanf("%d", &tmp); vv[i] = tmp; } if (t % 2) force(vv, 0, vv.size()); for (int i : vv) printf("%d ", i); printf("\n"); } void force(vector<int>& vv, int start, int end) { if (end - start == 1) { return; } int mid = (end+start)/2; force(vv, start, mid); force(vv, mid, end); for (int i = 0; i < mid-start; ++i) swap(vv[start+i], vv[mid+i]); }
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 | #include <iostream> #include <vector> #include <utility> #include <stdio.h> using namespace std; void force(vector<int>& vv, int start, int end); int main() { int n, t; scanf("%d %d", &n, &t); vector<int> vv(1<<n); for (int i = 0; i < (1<<n); ++i) { int tmp; scanf("%d", &tmp); vv[i] = tmp; } if (t % 2) force(vv, 0, vv.size()); for (int i : vv) printf("%d ", i); printf("\n"); } void force(vector<int>& vv, int start, int end) { if (end - start == 1) { return; } int mid = (end+start)/2; force(vv, start, mid); force(vv, mid, end); for (int i = 0; i < mid-start; ++i) swap(vv[start+i], vv[mid+i]); } |