记录编号 41383 评测结果 AAAAAAAA
题目名称 劣质的草 最终得分 100
用户昵称 Gravatar三木公 是否通过 通过
代码语言 Pascal 运行时间 0.077 s
提交时间 2012-07-22 15:26:00 内存使用 30.71 MiB
显示代码纯文本
var
a,b,c,i,j,k,m,n:longint;
r,s:array[0..2000,0..2000] of longint;

procedure
ss(x,y:longint);
begin
s[x,y]:=n;
r[x,y]:=1;
if (s[x-1,y]>0)and(x-1>0)and(r[x-1,y]=0)
 then ss(x-1,y);
if (s[x,y-1]>0)and(y-1>0)and(r[x,y-1]=0)
 then ss(x,y-1);
if (s[x+1,y]>0)and(x+1<=a)and(r[x+1,y]=0)
 then ss(x+1,y);
if (s[x,y+1]>0)and(y+1<=a)and(r[x,y+1]=0)
 then ss(x,y+1);

if (s[x-1,y-1]>0)and(x-1>0)and(y-1>0)and(r[x-1,y-1]=0)
 then ss(x-1,y-1);
if (s[x+1,y-1]>0)and(y-1>0)and(x+1<=a)and(r[x+1,y-1]=0)
 then ss(x+1,y-1);
if (s[x+1,y+1]>0)and(x+1<=a)and(y+1<=a)and(r[x+1,y+1]=0)
 then ss(x+1,y+1);
if (s[x-1,y+1]>0)and(y+1<=a)and(x-1>0)and(r[x-1,y+1]=0)
 then ss(x-1,y+1);

end;

begin
assign(input,'badgras.in');
reset(input);
assign(output,'badgras.out');
rewrite(output);

readln(a,b);
for i:=1 to a do
 for j:=1 to b do
 read(s[i,j]);

for i:=1 to a do
 for j:=1 to b do
  begin
  k:=0;
  if (s[i,j]>0)and(r[i,j]=0) then
    begin
    inc(n);
    ss(i,j);
    end;
  end;

write(n);

close(input);
close(output);
end.