Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n = 4;
- int m = 6;
- int matrix[100][100] = { {0, 0, 0, 1, 1, 2},
- {2, 0, 0, 0, 1, 0},
- {2, 0, 1, 0, 0, 0},
- {0, 0, 1, 0, 0, 2}
- };
- bool visited[100][100];
- const int dx[4] = {0, 0, 1, -1};
- const int dy[4] = {1, -1, 0 , 0};
- int inside(int i, int j)
- {
- return i >= 0 && i < n && j >= 0 && j < m;
- }
- void Fill(int i, int j, int elem)
- {
- visited[i][j] = true;
- for (int k = 0; k <= 3; ++k)
- if (inside(i + dx[k], j + dy[k]) && matrix[i + dx[k]][j + dy[k]] == elem)
- Fill(i + dx[k], j + dy[k], elem);
- }
- int CountAreas(int left1, int right1, int n, int m, int elem)
- {
- cout << "(" << left1 << "," << right1 << ")" << " (" << n << "," << m << ")\n";
- int l = n >> 1;
- int c = m >> 1;
- cout << "l = " << l << " c = " << c << endl << endl;
- if (left1 < n || right1 < m )
- {
- int z1 = CountAreas(left1, right1, l, c, elem); /// Z1
- int z2 = CountAreas(left1, c + 1, l, m, elem); /// Z2
- int z3 = CountAreas(l + 1, right1, n, c, elem); /// Z3
- int z4 = CountAreas(l + 1, c + 1, n, m, elem); /// Z4
- return z1 + z2 + z3 + z4;
- }
- else
- {
- // cout << "Here with " << "(" << left1 << ""
- if (!visited[left1][right1] && matrix[left1][right1] == elem)
- {
- Fill(left1, right1, elem);
- return 1;
- }
- return 0;
- }
- }
- int GetWinner()
- {
- int player1 = CountAreas(0, 0, n - 1, m - 1, 1);
- int player2 = CountAreas(0, 0, n - 1, m - 1, 2);
- return player1 > player2 ? 1 : 2;
- }
- int main()
- {
- for (int i = 0; i < n; ++i, cout << endl)
- for (int j = 0; j < m; ++j)
- cout << matrix[i][j] << " ";
- cout << endl << endl;
- cout << GetWinner();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement