#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
void print(vector<int> cards) {
// cout << "Cards: " << endl;
for (int card : cards)
cout << card << " ";
}
vector<int> shuffle(vector<int> cards ) {
if (cards.size() == 2) {
swap(cards[0],cards[1]);
// print(cards);
return cards;
}
else {
auto second(shuffle(vector<int>(cards.begin(),cards.begin()+cards.size()/2)));
auto first(shuffle(vector<int>(cards.begin()+cards.size()/2,cards.end())));
first.insert(first.end(),second.begin(),second.end());
return first;
}
}
int main () {
int n, t, tmp;
vector<int> cards;
cin >> n >> t;
// cout << "n: " << n << " t: " << t << endl;
for (int i=1; i<= pow(2,n); i++) {
cin >> tmp;
cards.push_back(tmp);
}
// print(cards);
auto shuffled_cards(shuffle(cards));
print(shuffled_cards);
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 | #include <iostream> #include <vector> #include <cmath> using namespace std; void print(vector<int> cards) { // cout << "Cards: " << endl; for (int card : cards) cout << card << " "; } vector<int> shuffle(vector<int> cards ) { if (cards.size() == 2) { swap(cards[0],cards[1]); // print(cards); return cards; } else { auto second(shuffle(vector<int>(cards.begin(),cards.begin()+cards.size()/2))); auto first(shuffle(vector<int>(cards.begin()+cards.size()/2,cards.end()))); first.insert(first.end(),second.begin(),second.end()); return first; } } int main () { int n, t, tmp; vector<int> cards; cin >> n >> t; // cout << "n: " << n << " t: " << t << endl; for (int i=1; i<= pow(2,n); i++) { cin >> tmp; cards.push_back(tmp); } // print(cards); auto shuffled_cards(shuffle(cards)); print(shuffled_cards); return 0; } |
English