Maxim_Leo

Untitled

May 19th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. #define n 6
  8.  
  9. int G[6][6]{
  10. {0, 1, 1, 0, 0, 0},
  11. {1, 0, 1, 1, 0, 0},
  12. {1, 1, 0, 1, 1, 0},
  13. {0, 1, 1, 0, 1, 1},
  14. {0, 0, 1, 1, 0, 1},
  15. {0, 0, 0, 1, 1, 0}
  16. };
  17.  
  18. void Lee(int S, int F) {
  19. S--;
  20. F--;
  21. int length, wawe[n];
  22. set<int> way;
  23. set<int> way1;
  24. set<int> way2;
  25. vector<int> NewFront, OldFront;
  26. for (int i = 0; i < n; i++)
  27. wawe[i] = -1;
  28.  
  29.  
  30. int mark=1;
  31. wawe[S] = mark;
  32. cout << "Wawe: " << endl;
  33. for (int k = 0; k < n; k++) {
  34. cout << wawe[k] << " ";
  35. }
  36. cout << endl;
  37. OldFront.push_back(S);
  38. cout << "NewFront: {} " << endl;
  39. cout << "OldFront: " <<S+1<< endl;
  40. way.insert(way.begin(), S);
  41. way1.insert(way1.begin(), S);
  42. way2.insert(way2.begin(), S);
  43. length = 0;
  44. cout << "Length " << length<<endl<<endl;
  45. while (true) {
  46. mark++;
  47. for (int i = 0; i < OldFront.size(); i++) {
  48.  
  49. for (int j = 0; j < n; j++) {
  50. if (G[OldFront[i]][j] == 1&&wawe[j]) {
  51. if (wawe[j] == -1) {
  52. if (j == F) {
  53. wawe[j]=mark;
  54. NewFront.push_back(j);
  55. way.insert(way.end(), j);
  56. way1.insert(way1.end(), j);
  57. way2.insert(way2.end(), j);
  58. break;
  59. }
  60.  
  61. wawe[j]=mark;
  62. }
  63.  
  64.  
  65. NewFront.push_back(j);
  66. if (NewFront.size()==1) way.insert(way.end(), NewFront[0]);
  67. if(NewFront.size() == 2) way1.insert(way1.end(), NewFront[1]);
  68. if (NewFront.size() == 2&&length!=1) way2.insert(way2.end(), NewFront[1]);
  69. if (NewFront.size() == 2 && length == 1) way2.insert(way2.end(), NewFront[0]);
  70. }
  71. }
  72. }
  73. cout << "Wawe: " << endl;
  74. for (int k = 0;k<n; k++) {
  75. cout <<wawe[k]<<" ";
  76. }
  77. cout << endl;
  78. cout << "NewFront: " << endl;
  79. for (int k = 0; k < NewFront.size(); k++) {
  80. cout << NewFront[k]+1 << " ";
  81. }
  82. cout << endl;
  83. cout << "OldFront: " << endl;
  84. for (int k = 0; k < OldFront.size(); k++) {
  85. cout << OldFront[k]+1 << " ";
  86. }
  87. cout << endl;
  88. cout << "length " << length+1 << endl;
  89. cout << endl;
  90. if (NewFront.empty()) {
  91. cout << "Нет пути";
  92. break;
  93. }
  94. for (int m = 0; m < NewFront.size(); m++) {
  95. if (NewFront[m] == F) {
  96. cout <<endl<< "Путь найден" << endl;
  97.  
  98. cout << endl;
  99. cout << "Путь 1";
  100. for (auto it:way) cout <<endl<< it+1<< " ";
  101. cout << endl;
  102. cout << "Длина 1 пути: " << length + 1;
  103. cout << endl;
  104. cout << "Путь 2";
  105. for (auto it1 : way1) cout << endl << it1 + 1 << " ";
  106. cout << endl;
  107. cout << "Длина 2 пути: " << length + 1;
  108. cout << endl;
  109. cout << "Путь 3";
  110. for (auto it2 : way2) cout << endl << it2 + 1 << " ";
  111. cout << endl;
  112. cout << "Длина 3 пути: " << length + 1 << endl;
  113. cout << "Путь: ";
  114. for (int d = F; d >= 0; d--) {
  115.  
  116. for (int j = 0; j < n; j++) {
  117. if (G[d][j] && wawe[d] - wawe[d - 1] == 1) cout << d << " ";
  118. }
  119. }
  120. cout <<"Длина пути: "<<length+1;
  121. return;
  122. }
  123. }
  124. OldFront = NewFront;
  125. NewFront = {};
  126. length++;
  127. }
  128.  
  129. }
  130.  
  131. int main()
  132. {
  133. setlocale(LC_ALL, "Russian");
  134. Lee(1, 6);
  135.  
  136. }
  137.  
  138.  
Advertisement
Add Comment
Please, Sign In to add comment