Advertisement
Guest User

8

a guest
Oct 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char a[100][100];
  6. int n,m, us[100][100], b[10] = {1, 0 , -1, 0, 0, 1, 0, -1}, col;
  7.  
  8. void dfs (int x, int y){
  9.   if (!x || !y || x > n || y > m) return;
  10.   col++;
  11.   us[x][y] = 1;
  12.   for (int i = 0; i < 8; i++){
  13.     if (a[x + b[i]][y + b[i + 1]] == '.' && !us[x + b[i]][y + b[i + 1]]){
  14.       dfs(x + b[i], y + b[i + 1]);
  15.     }
  16.   }
  17. }
  18.  
  19. int main (){
  20.   cin >> n;
  21.   m = n;
  22.   for (int i = 1; i <= n; i++){
  23.     for (int j = 1; j <= m; j++){
  24.       cin >> a[i][j];
  25.     }
  26.   }
  27.   int x, y;
  28.   cin >> x >> y;
  29.   dfs(x, y);  
  30.   cout << col;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement