```cpp
var
f:array[1..4,1..2]of longint;
a:array[0..500,0..500]of longint;
b:array[0..500,0..500]of boolean;
i,j,n,m,ans:longint;
x:ansistring;
function check(x,y:longint):boolean;
begin
if (x>0)and(x<=n)and(y>0)and(y<=m)and(a[x,y]<>1)and(b[x,y]=true) then exit(true);
exit(false);
end;
procedure dfs(x,y:longint);
var i:longint;
begin
b[x,y]:=false;
for i:=1 to 4 do
if check(x+f[i,1],y+f[i,2]) then
dfs(x+f[i,1],y+f[i,2]);
exit;
end;
begin
readln(n,m);
f[1,1]:=0; f[1,2]:=1;
f[2,1]:=1; f[2,2]:=0;
f[3,1]:=0; f[3,2]:=-1;
f[4,1]:=-1; f[4,2]:=0;
for i:=1 to n do
begin
readln(x);
for j:=1 to length(x) do
if x[j]='*' then a[i,j]:=1;
end;
fillchar(b,sizeof(b),true);
//dfs(1,1);
for i:=1 to m do
begin
if a[1,i]=0 then
dfs(1,i);
if a[n,i]=0 then
dfs(n,i);
end;
for j:=1 to n do
begin
if a[j,1]=0 then
dfs(j,1);
if a[j,m]=0 then
dfs(j,m);
end;
for i:=1 to n do
for j:=1 to m do
if (b[i,j])and(a[i,j]=0) then inc(ans);
write(ans);
end.
```
by bestzzy @ 2017-03-24 19:26:27
@[bestzzy](/space/show?uid=32854) 告诉我为什么
by Sakura_nameless @ 2017-04-01 19:33:00
@[樱木佐为](/space/show?uid=31010)
```cpp
var
map:array[0..501,0..501]of char;
x,y,i,j,ans,t,t2:longint;
procedure dfs(y,x:longint);
var
check:longint;
begin
map[y,x]:='1';
inc(t2);
if (map[y-1,x]='0')and(map[y-1,x]<>'5') then begin dfs(y-1,x); end;
if (map[y+1,x]='0')and(map[y+1,x]<>'5') then begin dfs(y+1,x); end;
if (map[y,x-1]='0')and(map[y,x-1]<>'5') then begin dfs(y,x-1); end;
if (map[y,x+1]='0')and(map[y,x+1]<>'5') then begin dfs(y,x+1); end;
end;
begin
readln(y,x);
for i:=0 to y+1 do
for j:=0 to x+1 do
map[i,j]:='5';
for i:=1 to y do
begin
for j:=1 to x do
begin
read(map[i,j]);
if map[i,j]='*' then inc(t);
end;
readln;
end;
for i:=1 to y do
if map[i,1]='0' then begin dfs(i,1); end;
for i:=1 to y do
if map[i,x]='0' then begin dfs(i,x); end;
for i:=1 to x do
if map[1,i]='0' then begin dfs(1,i); end;
for i:=1 to x do
if map[y,i]='0' then begin dfs(y,i); end;
ans:=x*y-t-t2;
write(ans);
end.
```
你的y不是行吗..
初始化成'5'没有边界.
by DPDPDPDP @ 2017-07-08 08:30:56