#include<iostream> #include<algorithm> #include<vector> using namespace std; vector<int> wekt; int main() { ios::sync_with_stdio(0); int a, b; int X, x, Y, y; int TKT = 0; cin >> a; cin >> b; for (int i = 1; i <= a; i++) { wekt.push_back(i); } do { X = 0; x = 0; for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { if (*it < x) { X++; } x = max(x, *it); } Y = 0; y = 0; reverse(wekt.begin(), wekt.end()); for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { if (*it < y) { Y++; } y = max(y, *it); } reverse(wekt.begin(), wekt.end()); if (Y == X) { TKT += 1; if (TKT == b) { cout << "TAK\n"; for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { cout << *it << " "; } return 0; } } } while (next_permutation(wekt.begin(), wekt.end()));//next_permutation <3 cout << "NIE"; //cin >> a; }
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 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include<iostream> #include<algorithm> #include<vector> using namespace std; vector<int> wekt; int main() { ios::sync_with_stdio(0); int a, b; int X, x, Y, y; int TKT = 0; cin >> a; cin >> b; for (int i = 1; i <= a; i++) { wekt.push_back(i); } do { X = 0; x = 0; for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { if (*it < x) { X++; } x = max(x, *it); } Y = 0; y = 0; reverse(wekt.begin(), wekt.end()); for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { if (*it < y) { Y++; } y = max(y, *it); } reverse(wekt.begin(), wekt.end()); if (Y == X) { TKT += 1; if (TKT == b) { cout << "TAK\n"; for (vector<int>::iterator it = wekt.begin(); it != wekt.end(); it++) { cout << *it << " "; } return 0; } } } while (next_permutation(wekt.begin(), wekt.end()));//next_permutation <3 cout << "NIE"; //cin >> a; } |