Guangsearch
# Include <iostream>
# Include <queue>
Using namespace STD;
Int map [8] [2] = {-}, {}, {0,-1}, {}, {-1,-1 }, {-1, 1}, {1,-1}, {1, 1 }};
Char gra [25] [25];
Struct Node
{
Int X;
Int y;
} Start, temp;
Int main ()
{
Int row, Col, posr, POSC;
Queue <node> qu;
While (CIN> row> Col> posr> POSC )&&! (ROW = 0 & Col = 0 & posr = 0 & POSC = 0 ))
{
Int I, J;
// Add a wall to the perimeter
For (I = 0; I <= row + 1; I ++)
For (j = 0; j <= Col + 1; j ++)
Gra [I] [J] = '.';
For (I = 1; I <= row; I ++)
For (j = 1; j <= Col; j ++)
Cin> gra [I] [J];
Start. x = posr;
Start. Y = POSC;
Qu. Push (start );
Gra [posr] [POSC] = '#';
Int sum = 0;
While (! Qu. Empty ())
{
Start = Qu. Front ();
Qu. Pop ();
Int X, Y;
// Determine whether there is an object around. If not, add 1 to the boundary.
For (I = 0; I <4; I ++)
{
X = start. x + map [I] [0];
Y = start. Y + map [I] [1];
If (GRA [x] [Y] = '.')
Sum ++;
}
For (I = 0; I <8; I ++)
{
X = start. x + map [I] [0];
Y = start. Y + map [I] [1];
If (GRA [x] [Y]! = '.' & Gra [x] [Y]! = '#')
{
Temp. x = X;
Temp. Y = y;
Qu. Push (temp );
Gra [x] [Y] = '#';
}
}
}
Cout <sum <Endl;
}
Return 0;
}