The_Law

Untitled

May 12th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. //mipt
  5. vector< vector<char> > b(8, vector<char> (8));
  6. vector< vector<bool> > used(8, vector<bool> (8, false));
  7.  
  8. void dfs(int i, int j, char col)
  9. {
  10.     if (col == b[i][j])
  11.         return;
  12.  
  13.     used[i][j] = true;
  14.     if (i != 0 && !used[i - 1][j])
  15.         dfs(i - 1, j, b[i][j]);
  16.     if (i != 7 && !used[i + 1][j])
  17.         dfs(i + 1, j, b[i][j]);
  18.     if (j != 0 && !used[i][j - 1])
  19.         dfs(i, j - 1, b[i][j]);
  20.     if (j != 7 && !used[i][j + 1])
  21.         dfs(i, j + 1, b[i][j]);
  22. }
  23.  
  24. int main()
  25. {
  26.     freopen("Board.in", "r", stdin);
  27.     freopen("Board.out", "w", stdout);
  28.  
  29.     for (int i = 0; i < 8; ++i)
  30.         for (int j = 0; j < 8; ++j)
  31.             cin >> b[i][j];
  32.  
  33.     int ans = 0;
  34.  
  35.     for (int i = 0; i < 8; ++i)
  36.         for (int j = 0; j < 8; ++j)
  37.             if (!used[i][j])
  38.             {
  39.                 dfs(i, j, b[i][j] + 1);
  40.                 ++ans;
  41.             }
  42.  
  43.     cout << ans;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment