Poj_3620
As long as you traverse each grid in sequence, find a grid with water, and then start with this grid for Deep Search or wide search, until the connected grid with water can be searched, then we will find the number of grids with water and Max For comparison. Max Update when large Max .
# Include < Stdio. h >
# Include < String . H >
Int A [ 110 ] [ 110 ], SX [ 1010 ], Sy [ 1010 ];
Int DX [] = { - 1 , 1 , 0 , 0 }, Dy [] = { 0 , 0 , - 1 , 1 };
Int Main ()
{
Int I, j, k, n, m, K, top, X, Y, newx, newy, Max, count;
While (Scanf ( " % D " , & N, & M, & K) = 3 )
{
Memset (, 0 , Sizeof ());
For (I = 0 ; I < K; I ++ )
{
Scanf ( " % D " , & X, & Y );
A [x] [Y] = 1 ;
}
Max = 0 ;
For (I = 1 ; I <= N; I ++ )
For (J = 1 ; J <= M; j ++ )
If (A [I] [J])
{
Top = 0 ;
Count = 0 ;
A [I] [J] = 0 ;
SX [Top] = I;
Sy [Top] = J;
Top ++ ;
Count ++ ;
While (Top > 0 )
{
Top -- ;
X = SX [Top];
Y = Sy [Top];
For (K = 0 ; K < 4 ; K ++ )
{
Newx = X + DX [k];
Newy = Y + Dy [k];
If (A [newx] [newy])
{
A [newx] [newy] = 0 ;
SX [Top] = Newx;
Sy [Top] = Newy;
Top ++ ;
Count ++ ;
}
}
}
If (Count > Max)
Max = Count;
}
Printf ( " % D \ n " , Max );
}
Return 0 ;
}