Advertisement
wojiaocbj

8conn

Jun 11th, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #pragma warning(disable:4996)
  7. int n, m;
  8. char map[114][514] = { 0 };
  9. void dfs(int x, int y){
  10.     if(map[x][y] == '.')return;
  11.     else{
  12.         map[x][y] = '.';
  13.         int dx, dy;
  14.         for(dx = -1; dx <= 1; dx++){
  15.             for(dy = -1; dy <= 1; dy++){
  16.                 if(x + dx >= 0 && x + dx < n && y + dy >= 0 && y + dy < m){
  17.                     dfs(x + dx, y + dy);
  18.                 }
  19.             }
  20.         }
  21.     }
  22. }
  23. int main(){
  24. #ifdef _DEBUG
  25.     freopen("../../../in.txt", "r", stdin);
  26. #endif
  27.     int i, j, ans = 0;
  28.     scanf("%d%d", &n, &m);
  29.     for(i = 0; i < n; i++){
  30.         scanf("%s", map[i]);
  31.     }
  32.     for(i = 0; i < n; i++){
  33.         for(j = 0; j < m; j++){
  34.             if(map[i][j] == 'W'){
  35.                 dfs(i, j); ans++;
  36.             }
  37.         }
  38.     }
  39.     printf("%d\n", ans);
  40. #ifdef _DEBUG
  41.     freopen("CON", "r", stdin);
  42.     system("pause");
  43. #endif
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement