Advertisement
ChoDog

D: for

Nov 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     vector<int> vec;
  10.     bool NevernayZhena = false;
  11.     int n, t;
  12.  
  13.     scanf("%d", &n);
  14.     scanf("%d", &t);
  15.  
  16.     for (int i = 1; i <= n / 2; i++) {
  17.         vec.push_back(i * 2);
  18.         vec.push_back(i * 2 - 1);
  19.     }
  20.     if (n % 2) {
  21.         vec.push_back(n);
  22.     }
  23.     else {
  24.         for (int i = 0; i < n; i++)
  25.             printf("%d%c", vec[i], ' ');
  26.         printf("\n");
  27.         t--;
  28.     }
  29.  
  30.  
  31.     while(next_permutation(vec.begin(), vec.end()) && t > 0) {
  32.         NevernayZhena = false;
  33.        
  34.  
  35.         for (int i = 0; i < n; i++) {
  36.             if (vec[i] == i + 1) {
  37.                 NevernayZhena = true;
  38.                 break;
  39.             }
  40.         }
  41.  
  42.         if (NevernayZhena) continue;
  43.         for (int i = 0; i < n; i++)
  44.             printf("%d%c", vec[i], ' ');
  45.         printf("\n");
  46.         t--;
  47.     }
  48.  
  49.     return 0;
  50.     system("pause");
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement