记录编号 |
41376 |
评测结果 |
AAAAAAAA |
题目名称 |
劣质的草 |
最终得分 |
100 |
用户昵称 |
H J H |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.114 s |
提交时间 |
2012-07-22 15:23:11 |
内存使用 |
7.79 MiB |
显示代码纯文本
var
a:array[1..2000,1..2000]of integer;
n,i,j,r,c,b,k:longint;
procedure dfs(x,y:longint);
BEGIN
if a[x,y]=1
then begin
a[x,y]:=2;
if (x-1>0) then dfs(x-1,y);
if (x+1<=r) then dfs(x+1,y);
if (y-1>0) then dfs(x,y-1);
if (y+1<=c) then dfs(x,y+1);
if (x-1>0)and(y-1>0) then dfs(x-1,y-1);
if (x+1<=r)and(y-1>0) then dfs(x+1,y-1);
if (x-1>0)and(y+1<=c) then dfs(x-1,y+1);
if (x+1<=r)and(y+1<=c) then dfs(x+1,y+1);
end;
END;
begin
assign(input,'badgras.in');
reset(input);
assign(output,'badgras.out');
rewrite(output);
fillchar(a,sizeof(a),0);
k:=0;
read(r,c);
for i:=1 to r do
for j:=1 to c do
begin
read(b);
if b>0 then a[i,j]:=1;
end;
for i:=1 to r do
for j:=1 to c do
if a[i,j]=1 then begin dfs(i,j); inc(k); end;
write(k);
close(input);
close(output);
end.