G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 4th, 2020 185 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n = 4;
  6. int m = 6;
  7. int matrix[100][100] = { {0, 0, 0, 1, 1, 2},
  8.                          {2, 0, 0, 0, 1, 0},
  9.                          {2, 0, 1, 0, 0, 0},
  10.                          {0, 0, 1, 0, 0, 2}
  11.                         };
  12. bool visited[100][100];
  13.  
  14. const int dx[4] = {0, 0, 1, -1};
  15. const int dy[4] = {1, -1, 0 , 0};
  16.  
  17. int inside(int i, int j)
  18. {
  19.     return i >= 0 && i < n && j >= 0 && j < m;
  20. }
  21.  
  22. void Fill(int i, int j, int elem)
  23. {
  24.  //   cout << "IN FILL\n";
  25.     visited[i][j] = true;
  26.     for (int k = 0; k <= 3; ++k)
  27.         if (inside(i + dx[k], j + dy[k]) && matrix[i + dx[k]][j + dy[k]] == elem && !visited[i + dx[k]][j + dy[k]])
  28.             Fill(i + dx[k], j + dy[k], elem);
  29.  
  30. //    cout << "OUT FILL\n";
  31. }
  32.  
  33. int validSubMatrix(int left1, int right1, int left2, int right2)
  34. {
  35.     return left1 <= left2 && right1 <= right2;
  36. }
  37.  
  38. int CountAreas(int left1, int right1, int n, int m, int elem)
  39. {
  40.     cout << "(" << left1 << "," << right1 << ")" << " (" << n << "," << m << ")\n";
  41.     int mijl = (n - left1) >> 1;
  42.     int mijc  = (m - right1) >> 1;
  43.    // cout << "l = " << mijl << " c = " << mijc << endl << endl;
  44.     if (left1 < n || right1 < m )
  45.     {
  46.         int z1, z2, z3, z4;
  47.         z1 = z2 = z3 = z4 = 0;
  48.         if (validSubMatrix(left1, right1, left1 + mijl, right1 + mijc))
  49.              z1 = CountAreas(left1, right1, left1 + mijl, right1 + mijc, elem); /// Z1
  50.         if (validSubMatrix(left1, right1 + mijc + 1, left1 + mijl, m))
  51.              z2 = CountAreas(left1, right1 + mijc + 1, left1 + mijl, m, elem); /// Z2
  52.         if (validSubMatrix(left1 + mijl + 1, right1 , n , right1 + mijc))
  53.             z3 = CountAreas(left1 + mijl + 1, right1, n, right1 + mijc, elem); /// Z3
  54.         if (validSubMatrix(left1 + mijl + 1, right1 + mijc + 1, n, m))
  55.             z4 = CountAreas(left1 + mijl + 1, right1 + mijc + 1, n, m, elem); /// Z4
  56.         return z1 + z2 + z3 + z4;
  57.     }
  58.     else
  59.     {
  60.      //   cout << "HERE\n";
  61.         if (!visited[left1][right1] && matrix[left1][right1] == elem)
  62.         {
  63.             Fill(left1, right1, elem);
  64.             return 1;
  65.         }
  66.         return 0;
  67.     }
  68. }
  69.  
  70. int GetWinner()
  71. {
  72.     int player1 = CountAreas(0, 0, n - 1, m - 1, 1);
  73.     int player2 = CountAreas(0, 0, n - 1, m - 1, 2);
  74.  
  75.     return player1 > player2 ? 1 : 2;
  76. }
  77.  
  78. int main()
  79. {
  80.  
  81.     for (int i = 0; i < n; ++i, cout << endl)
  82.         for (int j = 0; j < m; ++j)
  83.             cout << matrix[i][j] << " ";
  84.  
  85.     cout << endl << endl;
  86.     cout << GetWinner();
  87.     return 0;
  88. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top