#include <bits/stdc++.h> #define endl '\n' using namespace std; vector<int> V; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, t; cin >> n >> t; int pot = 1; while(n > 0) { pot *= 2; --n; } V.resize(pot); for(int i = 0; i < pot; ++i) cin >> V[i]; if(t%2 == 0) { for(int i = 0; i <= pot-1; ++i) cout << V[i] << " "; cout << endl; } else { for(int i = pot-1; i >= 0; --i) cout << V[i] << " "; cout << endl; } }
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 | #include <bits/stdc++.h> #define endl '\n' using namespace std; vector<int> V; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, t; cin >> n >> t; int pot = 1; while(n > 0) { pot *= 2; --n; } V.resize(pot); for(int i = 0; i < pot; ++i) cin >> V[i]; if(t%2 == 0) { for(int i = 0; i <= pot-1; ++i) cout << V[i] << " "; cout << endl; } else { for(int i = pot-1; i >= 0; --i) cout << V[i] << " "; cout << endl; } } |