NYOJ--27--dfs--水池数目

时间:2021-11-23 19:22:53
/*
    Name: NYOJ--27--水池数目
    Author: shen_渊
    Date: 17/04/17 15:42
    Description: 经典dfs水题,,,
*/
#include<iostream>
#include<cstring>
using namespace std;
][],ct;
void dfs(int,int);
][] = {
                    {,},
                    {,-},
                    {,},
                    {-,},
                };//4个方向递归
int main()
{
    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
    int N;cin>>N;
    while(N--)
    {
        cin>>m>>n;
        ct = ;
        memset(map,,sizeof(map));
        ; i<m; ++i){
            ; j<n; ++j){
                cin>>map[i][j];
            }
        }
        ; i<m; ++i){
            ; j<n; ++j){
                ){
                    map[i][j] = ;
                    ct++;
                    dfs(i,j);
                }
            }
        }
        cout<<ct<<endl;
    }
    ;
}
void dfs(int x,int y){
    ; i<; ++i){
        ];
        ];
         || b< || a>=m || b>=n || map[a][b] == )continue;
        map[a][b] = ;
        dfs(a,b);
    }
}