#include <cstdio> #include <iostream> #include <math.h> #include <algorithm> using namespace std; int n, t, x; int kar[2000000]; void tasuj(int p, int k) { if(p == k) return; int s = (p+k)/2; tasuj(p, s); tasuj(s+1, k); for(int i = p; i <= s; i++) swap(kar[i], kar[s+1+i-p]); return; } int main() { scanf("%d %d", &n, &t); x = pow(2, n); for(int i = 1; i <= x; i++) scanf("%d", &kar[i]); if(t % 2 == 1) tasuj(1, x); for(int i = 1; i <= x; i++) printf("%d ", kar[i]); 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 | #include <cstdio> #include <iostream> #include <math.h> #include <algorithm> using namespace std; int n, t, x; int kar[2000000]; void tasuj(int p, int k) { if(p == k) return; int s = (p+k)/2; tasuj(p, s); tasuj(s+1, k); for(int i = p; i <= s; i++) swap(kar[i], kar[s+1+i-p]); return; } int main() { scanf("%d %d", &n, &t); x = pow(2, n); for(int i = 1; i <= x; i++) scanf("%d", &kar[i]); if(t % 2 == 1) tasuj(1, x); for(int i = 1; i <= x; i++) printf("%d ", kar[i]); return 0; } |