比赛 暑假培训B班二测 评测结果 MMMMMMMM
题目名称 劣质的草 最终得分 0
用户昵称 三木公 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-22 10:34:22
显示代码纯文本
var
a,b,c,i,j,k,m,n:longint;
r,s:array[0..10000,0..10000] 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.