Lrapava

ამოხსნა

Mar 8th, 2021 (edited)
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int checked = 0;
  5. std::vector <int> v[6];
  6.  
  7. bool useColors = true;
  8.  
  9. int check(int x) {
  10.     int arr[6][4];
  11.     for (int i = 0; i < 4; i++) {
  12.         for (int j = 0; j < 6; j++) {
  13.             arr[j][i] = v[j][x % checked];
  14.         }
  15.         x /= checked;
  16.     }
  17.     int maxs = -1;
  18.     for (int i = 0; i < 5; i++) {
  19.         for (int j = i + 1; j < 6; j++) {
  20.             int same = 0;
  21.             for (int k = 0; k < 4; k++) {
  22.                 if (arr[i][k] == arr[j][k]) same++;
  23.             }
  24.             maxs = std::max(maxs, same);
  25.         }
  26.     }
  27.     return maxs;
  28. }
  29.  
  30. int main() {
  31.    
  32.     for (int i = 0; i < 6; i++) v[i].resize(15, 2);
  33.  
  34.     int fst = 0;
  35.    
  36.     for (int snd = fst + 1; snd < 6; snd++) {
  37.         int trd = (snd == 1) ? 2 : 1;
  38.         for (int fth = 2; fth < 6; fth++) {
  39.             if (fth == trd || fth == snd) continue;
  40.             v[fst][checked] = 0;
  41.             v[snd][checked] = 0;
  42.             v[trd][checked] = 1;
  43.             v[fth][checked] = 1;
  44.             checked++;
  45.         }
  46.     }
  47.  
  48.     int lim = checked * checked * checked * checked;
  49.  
  50.     std::pair <int, int> best = {99999, 99999};
  51.     for (int i = 0; i < lim; i++) {
  52.         int res = check(i);
  53.         if (res < best.first) best = {res, i};
  54.     }
  55.  
  56.     int x = best.second;
  57.     std::cout << "თანაკვეთების მაქსიმალური რაოდენობა: " << best.first << "\n";
  58.     for (int i = 0; i < 4; i++) {
  59.         for (int j = 0; j < 6; j++) {
  60.             if (useColors == true) std::cout << "\033[4" << v[j][x%checked] + 1  << "m";
  61.             std::cout << v[j][x%checked];
  62.             if (useColors) std::cout << "\033[0m";
  63.         }
  64.         std::cout << "\n";
  65.         x /= checked;
  66.     }
  67. }
  68.  
Add Comment
Please, Sign In to add comment