Advertisement
Sanlover

Untitled

Mar 8th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <vector>
  4. #include <string>
  5. #include <iomanip>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. vector<vector<int>> moves;
  10. vector<vector<vector<int>>> a3;
  11. vector < vector <int> > act;
  12.  
  13. void backTracking(int pos, vector < vector <int> >& act)
  14. {
  15. bool isAdded = false;
  16. for (int i = 0; i < act.size(); i++) {
  17. bool isFound = false;
  18. for (const auto& it : moves)
  19. if (it == act[i]) {
  20. isFound = true;
  21. break;
  22. }
  23. if (!isFound) {
  24. moves.push_back(act[i]);
  25. backTracking(pos + 1, act);
  26. }
  27. }
  28. if (!moves.empty())
  29. a3.push_back(moves);
  30. if (!moves.empty())
  31. moves.pop_back();
  32. }
  33.  
  34. int main()
  35. {
  36. SetConsoleCP(1251); SetConsoleOutputCP(1251);
  37. cout << "Вводите координаты точек через пробел." << endl;
  38. vector<int> a;
  39. int t;
  40. cout << "По окончание ввода введите пустую строку." << std::endl;
  41. do {
  42. cin >> t;
  43. a.push_back(t);
  44. } while (getchar() != '\n');
  45. int n = a.size();
  46. sort(a.begin(), a.end());
  47. cout << "Вводите координаты начала и конца прямых." << endl;
  48. vector<int> b;
  49. vector<int> c;
  50. int t1, t2;
  51. do {
  52. cin >> t1 >> t2;
  53. b.push_back(t1);
  54. c.push_back(t2);
  55. cout << endl;
  56. } while (getchar() != '\n');
  57. int k = b.size();
  58. int** aa = new int* [n];
  59. for (int i = 0; i < n; i++) {
  60. aa[i] = new int[k];
  61. for (int i1 = 0; i1 < k; i1++)
  62. aa[i][i1] = 0;
  63. }
  64. int p = 0, min = n, r;
  65. for (int i = 0; i < n; i++) {
  66. for (int i1 = 0; i1 < k; i1++) {
  67. if ((a[i] >= b[i1]) && (a[i] <= c[i1])) {
  68. p++;
  69. aa[i][i1] = 1;
  70. }
  71. }
  72. if (p == 0) {
  73. cout << "Не покроет";
  74. exit;
  75. }
  76. if (p < min) {
  77. min = p;
  78. r = i;
  79. }
  80. p = 0;
  81. }
  82. cout << "Массив пересечений:" << endl;
  83. for (int i = 0; i < n; ++i) {
  84. for (int i1 = 0; i1 < k; ++i1) {
  85. cout << aa[i][i1] << ' ';
  86. }
  87. cout << endl;
  88. }
  89. vector < vector <int> > act(k, vector <int>(n));
  90. cout << endl;
  91. cout << "Векторы: " << endl;
  92. for (int i = 0; i < k; i++) {
  93. for (int i1 = 0; i1 < n; i1++) {
  94. act[i][i1] = aa[i1][i];
  95. cout << act[i][i1];
  96. }
  97. cout << endl;
  98. }
  99. backTracking(0, act);
  100.  
  101. cout << endl;
  102. size_t counter = 1;
  103. for (size_t i = 0; i < a3.size(); i++)
  104. {
  105. cout << counter++ << ") ";
  106. for (size_t j = 0; j < a3[i].size(); j++)
  107. {
  108. for (size_t l = 0; l < a3[i][j].size(); l++)
  109. {
  110. cout << setw(2) << a3[i][j][l];
  111. }
  112. if (j + 1 < a3[i].size())
  113. cout << " -";
  114. }
  115. cout << endl;
  116. }
  117. return 0;
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement