#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
int n; // exponent of two: 1..20
int t; // number of shuffles: 1..10^9
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin >> n >> t;
std::vector<int> v(1 << n);
std::copy_n(std::istream_iterator<int>(std::cin), 1 << n, v.begin());
if (t % 2 == 0)
std::move(std::begin(v), std::end(v), std::ostream_iterator<int>(std::cout, " "));
else
std::move(v.rbegin(), v.rend(), std::ostream_iterator<int>(std::cout, " ")); // C++11
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <vector> #include <iterator> #include <algorithm> int n; // exponent of two: 1..20 int t; // number of shuffles: 1..10^9 int main() { std::ios_base::sync_with_stdio(false); std::cin >> n >> t; std::vector<int> v(1 << n); std::copy_n(std::istream_iterator<int>(std::cin), 1 << n, v.begin()); if (t % 2 == 0) std::move(std::begin(v), std::end(v), std::ostream_iterator<int>(std::cout, " ")); else std::move(v.rbegin(), v.rend(), std::ostream_iterator<int>(std::cout, " ")); // C++11 } |
English