题目背景
oibh总部突然被水淹没了!现在需要你的救援……
题目描述
oibh被突来的洪水淹没了>.<还好oibh总部有在某些重要的地方起一些围墙,用*号表示,而一个封闭的*号区域洪水是进不去的……现在给出oibh的围墙建设图,问oibh总部没被淹到的重要区域(由"0"表示)有多少。
输入输出格式
输入格式:
第一行是两个数,x和y(x,y<=500)
第二行及以下是一个由*和0组成的x*y的图。
输出格式:
输出没被水淹没的oibh总部的“0”的数量。
输入输出样例
样例输入1 4 5 00000 00*00 0*0*0 00*00 样例输入2 5 5 ***** *0*0* **0** *0*0* *****
var map:array[0..550,0..550]of char;
n,m,j,i,ans:longint;
procedure flood(x,y:longint);
begin
map[x,y]:='*';
if (y-1>=1)and(map[x,y-1]='0')then flood(x,y-1);
if (x+1<=n)and(map[x+1,y]='0')then flood(x+1,y);
if (x-1>=1)and(map[x-1,y]='0')then flood(x-1,y);
if (y+1<=m)and(map[x,y+1]='0')then flood(x,y+1);
end;
begin
while not eof do
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(map[i,j]);
readln;
end;
for i:=1 to n do
begin
if map[i,1]='0' then flood(i,1);
if map[i,m]='0' then flood(i,m);
end;
for i:=1 to m do
begin
if map[1,i]='0' then flood(1,i);
if map[n,i]='0' then flood(n,i);
end;
ans:=0;
for i:=1 to n do
for j:=1 to m do
if map[i,j]='0' then inc(ans);
writeln(ans);
end;
end.