比赛 暑假培训B班二测 评测结果 AAAAAAAA
题目名称 劣质的草 最终得分 100
用户昵称 H J H 运行时间 0.346 s
代码语言 Pascal 内存使用 7.79 MiB
提交时间 2012-07-22 09:53:13
显示代码纯文本
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.