Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <conio.h>
- #include <windows.h>
- #define N 7
- using namespace std;
- enum ConsoleColor {
- Black = 0,
- Blue = 1,
- Green = 2,
- Cyan = 3,
- Red = 4,
- Magenta = 5,
- Brown = 6,
- LightGray = 7,
- DarkGray = 8,
- LightBlue = 9,
- LightGreen = 10,
- LightCyan = 11,
- LightRed = 12,
- LightMagenta = 13,
- Yellow = 14,
- White = 15
- };
- bool zero(int *a, int n);
- int main()
- {
- setlocale(LC_ALL, "rus");
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
- int b[N] = {};
- int a[N][N] =
- {
- {0, 3, 0, 0, 0, 30, 80},
- {3, 0, 2, 0, 0, 0, 17},
- {0, 2, 0, 70, 0, 0, 14},
- {0, 0, 70, 0, 4, 0, 20},
- {0, 0, 0, 4, 0, 40, 50},
- {30, 0, 0, 0, 40, 0, 8},
- {80, 17, 14, 20, 50, 8, 0}
- };
- /*{
- {0, 20, 0, 0, 0, 23, 1},
- {20, 0, 5, 0, 0, 0, 4},
- {0, 5, 0, 3, 0, 0, 9},
- {0, 0, 3, 0, 17, 0, 16},
- {0, 0, 0, 17, 0, 28, 25},
- {23, 0, 0, 0, 28, 0, 36},
- {1, 4, 9, 16, 25, 36, 0}
- };*/
- int color[N] = {0, 1, 2, 3, 4, 5, 6};
- int ways[N][2] = {};
- //int x[N] = {0, 0, 0, 0, 1, 0, 0};
- //cout << equals(x, N) << endl;;
- int count = 0;
- cout << "погнали";
- do
- {
- cout << "\n\nПУТИ: ";
- for (int k = 0; k < N; k++)
- cout << b[k] << " ";
- int minWay = 999999999;
- int minWayI, minWayJ;
- for (int i = 0; i < N; i++)
- {
- for (int j = i; j < N; j++)
- {
- if (a[i][j] != 0 && a[i][j] < minWay)
- {
- minWay = a[i][j];
- minWayI = i;
- minWayJ = j;
- }
- }
- }
- cout << "\nМинимальный путь = " << minWay << " между вершинами ";
- cout << minWayI + 1 << " и " << minWayJ + 1 << " ";
- if(color[minWayI] != color[minWayJ] && b[minWayI] <= 1 && b[minWayJ] <= 1)
- {
- SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | Green));
- cout << "БЕРЕМ!";
- SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
- int x = min(color[minWayI], color[minWayJ]);
- int y = max(color[minWayI], color[minWayJ]);
- color[minWayI] = x;
- color[minWayJ] = x;
- for (int kx = 0; kx < N; kx++)
- {
- if (color[kx] == y)
- color[kx] = x;
- }
- ways[count][0] = minWayI;
- ways[count][1] = minWayJ;
- //cout << minWayI << " " << minWayJ << endl;
- count++;
- b[minWayI] ++;
- b[minWayJ] ++;
- cout << "\nМассив красок: ";
- for(int i = 0; i < N; i++)
- cout << color[i] + 1 <<" ";
- _getch();
- }
- else
- {
- SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | Red));
- cout << "НЕ БЕРЕМ!";
- SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
- }
- a[minWayI][minWayJ] = 999999;
- } while(!zero(color, N));
- return 0;
- }
- bool zero(int *a, int n)
- {
- bool OK = true;
- for (int i = 0; i < n - 1; i++)
- {
- if (a[i] != a[i + 1])
- {
- OK = false;
- break;
- }
- }
- return OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement