Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void ravno(vector<vector<int>> &a, vector<vector<int>> &b)
- {
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- a[i][j] = b[i][j];
- }
- }
- }
- int main()
- {
- int n = 16;
- vector<vector<int>> field(4, vector<int>(4, 0));
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- cin >> field[i][j];
- if (field[i][j] == 'W')
- field[i][j] = 0;
- else
- field[i][j] = 1;
- }
- }
- vector<vector<int>> mas(3, vector<int>(3));
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- cin >> mas[i][j];
- }
- }
- int mn = 17;
- vector<vector<int>> wb;
- ravno(wb, field);
- for (int mask = 0; mask < (1 << n); mask++)
- {
- int k = 0;
- for (int j = 0; j < n; j++)
- {
- if (mask & (1 << j))
- {
- k++;
- int xx = mask / 4;
- int yy = mask % 4;
- for (int x = xx - 1; x <= xx + 1; x++)
- {
- for (int y = yy - 1; y <= yy + 1; y++)
- {
- if (x >= 0 && x < 4 && y >= 0 && y < 4)
- {
- if (mas[x - xx + 1][y - yy + 1] == 1)
- {
- wb[x][y] = (wb[x][y] + 1) & 2;
- }
- }
- }
- }
- }
- }
- int sum = 0;
- for (int x = 0; x < 4; x++)
- {
- for (int y = 0; y < 4; y++)
- {
- sum += wb[x][y];
- }
- }
- if (sum == 0 || sum == 16)
- {
- mn = min(mn, k);
- }
- ravno(wb, field);
- }
- if (mn == 17)
- cout << "Impossible";
- else
- cout << mn;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement