#include <bits/stdc++.h> using namespace std; static int Karty [1050000]; void TAS (int a, int b) { if (b-a == 1) { swap(Karty[b], Karty[a]); return; } int x = (a+b+1) / 2; for (int it = 0; it < x-a; it++) { swap(Karty[a+it], Karty[x+it]); } TAS(x, b); TAS(a, x-1); return; }; int main() { //ios_base::sync_with_stdio(0); int n, t, m = 1; scanf("%d%d", &n, &t); while(n--) m *= 2; for (int i = 0; i < m; i++) { scanf("%d", &Karty[i]); } t = t % m; while(t--) TAS(0, m-1); for (int i = 0; i < m; i++) printf("%d ", Karty[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 40 | #include <bits/stdc++.h> using namespace std; static int Karty [1050000]; void TAS (int a, int b) { if (b-a == 1) { swap(Karty[b], Karty[a]); return; } int x = (a+b+1) / 2; for (int it = 0; it < x-a; it++) { swap(Karty[a+it], Karty[x+it]); } TAS(x, b); TAS(a, x-1); return; }; int main() { //ios_base::sync_with_stdio(0); int n, t, m = 1; scanf("%d%d", &n, &t); while(n--) m *= 2; for (int i = 0; i < m; i++) { scanf("%d", &Karty[i]); } t = t % m; while(t--) TAS(0, m-1); for (int i = 0; i < m; i++) printf("%d ", Karty[i]); return 0; } |