Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void ravno(vector<vector<int>> &a, vector<vector<int>> &b)
  5. {
  6. for (int i = 0; i < 4; i++)
  7. {
  8. for (int j = 0; j < 4; j++)
  9. {
  10. a[i][j] = b[i][j];
  11. }
  12. }
  13. }
  14.  
  15.  
  16. int main()
  17. {
  18. int n = 16;
  19. vector<vector<int>> field(4, vector<int>(4, 0));
  20. for (int i = 0; i < 4; i++)
  21. {
  22. for (int j = 0; j < 4; j++)
  23. {
  24. cin >> field[i][j];
  25. if (field[i][j] == 'W')
  26. field[i][j] = 0;
  27. else
  28. field[i][j] = 1;
  29. }
  30. }
  31. vector<vector<int>> mas(3, vector<int>(3));
  32. for (int i = 0; i < 3; i++)
  33. {
  34. for (int j = 0; j < 3; j++)
  35. {
  36. cin >> mas[i][j];
  37. }
  38. }
  39. int mn = 17;
  40. vector<vector<int>> wb;
  41. ravno(wb, field);
  42. for (int mask = 0; mask < (1 << n); mask++)
  43. {
  44. int k = 0;
  45. for (int j = 0; j < n; j++)
  46. {
  47. if (mask & (1 << j))
  48. {
  49. k++;
  50. int xx = mask / 4;
  51. int yy = mask % 4;
  52. for (int x = xx - 1; x <= xx + 1; x++)
  53. {
  54. for (int y = yy - 1; y <= yy + 1; y++)
  55. {
  56. if (x >= 0 && x < 4 && y >= 0 && y < 4)
  57. {
  58. if (mas[x - xx + 1][y - yy + 1] == 1)
  59. {
  60. wb[x][y] = (wb[x][y] + 1) & 2;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. int sum = 0;
  68. for (int x = 0; x < 4; x++)
  69. {
  70. for (int y = 0; y < 4; y++)
  71. {
  72. sum += wb[x][y];
  73. }
  74. }
  75. if (sum == 0 || sum == 16)
  76. {
  77. mn = min(mn, k);
  78. }
  79. ravno(wb, field);
  80. }
  81. if (mn == 17)
  82. cout << "Impossible";
  83. else
  84. cout << mn;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement