Description
一矩形阵列由数字0到9组成,数字1到9代表细胞,细胞的定义为沿细胞数字上下左右还是细胞数字则为同一细胞,求给定矩形阵列的细胞个数。
Input
整数m,n(m行,n列)1<=N,M<=100
Output
细胞的个数
Sample Input
4 10
0234500067
1034560500
2045600671
0000000089
Sample Output
4
其实就是找连通块,将0标记为0,其他数字标记为1,再统计为1的连通块数量。
#include<bits/stdc++.h>
using namespace std;
int n,m;
int ans=0;
int mp[1010][1010];
bool vis[1010][1010];
int dir[4][2]={
{1,0},{-1,0},{0,1},{0,-1}};
void dfs(int x,int y){
vis[x][y]=1;
for(int i=0;i<4;i++){
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(!vis[tx][ty] && mp[tx][ty]==1){
dfs(tx,ty);
}
}
return;
}
void check(