http://www.bnuoj.com/bnuoj/problem_show.php?pid=3739
搜索题,就是找到里面联通区域最大值
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,k,now,ma,p;
int a[110][110];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
void Dfs(int x, int y)
{
int i,nx,ny;
a[x][y] = p; //标记走过
now++;
for(i = 0; i < 4; i++)
{
nx = x+dir[i][0];
ny = y+dir[i][1];
if(a[nx][ny]==1)
{
Dfs(nx,ny);
}
}
return ;
}
int main()
{
int i,j,x,y;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(a,0,sizeof(a));
ma = 0;
for(i = 0; i < k; i++)
{
scanf("%d%d",&x,&y);
a[x][y] = 1;
}
p = 1;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
{
if(a[i][j] == 1)
{
p++;
now = 0;
Dfs(i,j);
if(ma<now) ma=now;
}
}
}
printf("%d\n",ma);
}
return 0;
}