#include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; void myswap(vector<int>& v, int j, int k) { int begin = j*k; int p = begin + k/2; int t = k/2; for(int i=begin; i<p; i++) { std::swap(v[i], v[i+t]); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, t; cin >> n >> t; int num = std::pow(2, n); std::vector<int> cards (num, 0); for(int i = 0; i<num; i++) { cin >> cards[i]; } int m = 2; for(int k=0; k<t; k++) { for(int j = 1; j<=n; j++) { int p = num/m; for(int i = 0; i<p; i++) { myswap(cards, i, m); } m = m * 2; } } for(int i = 0; i<num; i++) { cout << cards[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 41 42 43 | #include <iostream> #include <algorithm> #include <vector> #include <cmath> using namespace std; void myswap(vector<int>& v, int j, int k) { int begin = j*k; int p = begin + k/2; int t = k/2; for(int i=begin; i<p; i++) { std::swap(v[i], v[i+t]); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, t; cin >> n >> t; int num = std::pow(2, n); std::vector<int> cards (num, 0); for(int i = 0; i<num; i++) { cin >> cards[i]; } int m = 2; for(int k=0; k<t; k++) { for(int j = 1; j<=n; j++) { int p = num/m; for(int i = 0; i<p; i++) { myswap(cards, i, m); } m = m * 2; } } for(int i = 0; i<num; i++) { cout << cards[i] << " "; } return 0; } |