#include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; template <class it> void tasuj(it first, it last) { if (last-first == 2) { swap (*first, *(first+1)); }else { it mid = first + (last-first)/2; swap_ranges(first,mid,mid); tasuj(first,mid); tasuj(mid,last); } } int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); int n, t; vector <int> tab; cin>>n>>t; tab.resize(1<<n); for (int i=0;i<(1<<n);i++) { cin>>tab[i]; } if (t%2==1) reverse(begin(tab),end(tab)); for (int i=0;i<(1<<n);i++) { cout<<tab[i]<<" "; } cout<<endl; 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 44 45 46 47 48 | #include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; template <class it> void tasuj(it first, it last) { if (last-first == 2) { swap (*first, *(first+1)); }else { it mid = first + (last-first)/2; swap_ranges(first,mid,mid); tasuj(first,mid); tasuj(mid,last); } } int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); int n, t; vector <int> tab; cin>>n>>t; tab.resize(1<<n); for (int i=0;i<(1<<n);i++) { cin>>tab[i]; } if (t%2==1) reverse(begin(tab),end(tab)); for (int i=0;i<(1<<n);i++) { cout<<tab[i]<<" "; } cout<<endl; return 0; } |