Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- using namespace std;
- int main() {
- int n, t, tmp;
- cin >> n >> t;
- vector <int> a(n, 0);
- for (int i = 1; i < n + 1; i++)
- a[i-1] = i;
- if (n % 2 == 0) {
- for (int i = 0; i < n; i += 2) {
- tmp = a[i];
- a[i] = a[i + 1];
- a[i + 1] = tmp;
- }
- }
- else {
- for (int i = 0; i < n-1; i += 2) {
- tmp = a[i];
- a[i] = a[i + 1];
- a[i + 1] = tmp;
- }
- tmp = a[n - 1];
- a[n - 1] = a[n - 2];
- a[n - 2] = tmp;
- }
- for (int i = 0; i < n; i++)
- printf("%d ", a[i]);
- printf("\n");
- int c = 1;
- bool f = false;
- while (c != t) {
- f = false;
- next_permutation(a.begin(), a.end());
- for (int i = 0;i < n; i++)
- if (a[i] == i + 1) {
- f = true;
- break;
- }
- if (!f) {
- for (int i = 0; i < n; i++)
- printf("%d ", a[i]);
- printf("\n");
- c++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement