Advertisement
Guest User

for

a guest
Nov 26th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <conio.h>
  5. #include <windows.h>
  6. #define N 7
  7. using namespace std;
  8. enum ConsoleColor {
  9.     Black = 0,
  10.     Blue = 1,
  11.     Green = 2,
  12.     Cyan = 3,
  13.     Red = 4,
  14.     Magenta = 5,
  15.     Brown = 6,
  16.     LightGray = 7,
  17.     DarkGray = 8,
  18.     LightBlue = 9,
  19.     LightGreen = 10,
  20.     LightCyan = 11,
  21.     LightRed = 12,
  22.     LightMagenta = 13,
  23.     Yellow = 14,
  24.     White = 15
  25. };
  26. bool zero(int *a, int n);
  27. int main()
  28. {
  29.     setlocale(LC_ALL, "rus");
  30.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  31.     SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
  32.     int b[N] = {};
  33.     int a[N][N] =
  34.     {
  35.         {0, 3, 0, 0, 0, 30, 80},
  36.         {3, 0, 2, 0, 0, 0, 17},
  37.         {0, 2, 0, 70, 0, 0, 14},
  38.         {0, 0, 70, 0, 4, 0, 20},
  39.         {0, 0, 0, 4, 0, 40, 50},
  40.         {30, 0, 0, 0, 40, 0, 8},
  41.         {80, 17, 14, 20, 50, 8, 0}
  42.     };
  43.     /*{
  44.         {0, 20, 0, 0, 0, 23, 1},
  45.         {20, 0, 5, 0, 0, 0, 4},
  46.         {0, 5, 0, 3, 0, 0, 9},
  47.         {0, 0, 3, 0, 17, 0, 16},
  48.         {0, 0, 0, 17, 0, 28, 25},
  49.         {23, 0, 0, 0, 28, 0, 36},
  50.         {1, 4, 9, 16, 25, 36, 0}
  51.     };*/
  52.  
  53.     int color[N] = {0, 1, 2, 3, 4, 5, 6};
  54.     int ways[N][2] = {};
  55.  
  56.     //int x[N] = {0, 0, 0, 0, 1, 0, 0};
  57.     //cout << equals(x, N) << endl;;
  58.  
  59.     int count = 0;
  60.     cout << "погнали";
  61.     do
  62.     {
  63.         cout << "\n\nПУТИ: ";
  64.         for (int k = 0; k < N; k++)
  65.             cout << b[k] << " ";
  66.  
  67.         int minWay = 999999999;
  68.         int minWayI, minWayJ;
  69.         for (int i = 0; i < N; i++)
  70.         {
  71.             for (int j = i; j < N; j++)
  72.             {
  73.                 if (a[i][j] != 0 && a[i][j] < minWay)
  74.                 {
  75.                     minWay = a[i][j];
  76.                     minWayI = i;
  77.                     minWayJ = j;
  78.                 }
  79.             }
  80.         }
  81.  
  82.         cout << "\nМинимальный путь = " << minWay << " между вершинами ";
  83.         cout << minWayI + 1 << " и " << minWayJ + 1 << " ";
  84.  
  85.  
  86.         if(color[minWayI] != color[minWayJ] && b[minWayI] <= 1 && b[minWayJ] <= 1)
  87.         {
  88.             SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | Green));
  89.             cout << "БЕРЕМ!";
  90.             SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
  91.             int x = min(color[minWayI], color[minWayJ]);
  92.             int y = max(color[minWayI], color[minWayJ]);
  93.             color[minWayI] = x;
  94.             color[minWayJ] = x;
  95.             for (int kx = 0; kx < N; kx++)
  96.             {
  97.                 if (color[kx] == y)
  98.                     color[kx] = x;
  99.             }
  100.  
  101.             ways[count][0] = minWayI;
  102.             ways[count][1] = minWayJ;
  103.             //cout << minWayI << " " << minWayJ << endl;
  104.             count++;
  105.  
  106.             b[minWayI] ++;
  107.             b[minWayJ] ++;
  108.  
  109.             cout << "\nМассив красок: ";
  110.             for(int i = 0; i < N; i++)
  111.                 cout << color[i] + 1 <<" ";
  112.             _getch();
  113.         }
  114.         else
  115.         {
  116.             SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | Red));
  117.             cout << "НЕ БЕРЕМ!";
  118.             SetConsoleTextAttribute(hConsole, (WORD) ((Black << 4) | White));
  119.         }
  120.         a[minWayI][minWayJ] = 999999;
  121.     } while(!zero(color, N));
  122.     return 0;
  123. }
  124. bool zero(int *a, int n)
  125. {
  126.     bool OK = true;
  127.     for (int i = 0; i < n - 1; i++)
  128.     {
  129.         if (a[i] != a[i + 1])
  130.         {
  131.             OK = false;
  132.             break;
  133.         }
  134.     }
  135.     return OK;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement