| 比赛 | 暑假培训B班二测 | 评测结果 | AAAAAAEA | 
    | 题目名称 | 劣质的草 | 最终得分 | 87 | 
    | 用户昵称 | Fangel | 运行时间 | 0.087 s | 
    | 代码语言 | Pascal | 内存使用 | 0.28 MiB | 
    | 提交时间 | 2012-07-22 11:01:40 | 
显示代码纯文本
var
a,b,c,d,m,n,i,j:longint;
ss:array[1..100,1..100] of longint;
line:array[0..10000,1..2] of longint;
//-----------------------------------------------------------------------
procedure lin(x,y:longint);
begin
inc(j);
line[j,1]:=x;
line[j,2]:=y;
end;
//-----------------------------------------------------------------------
procedure lout(var x,y:longint);
begin
inc(i);
x:=line[i,1];
y:=line[i,2];
end;
//-----------------------------------------------------------------------
procedure flood(x,y:longint);
begin
fillchar(line,sizeof(line),0);
   ss[x,y]:=0;
   lin(x,y);
   while i<j do
    begin
    lout(x,y);
    if (y>1) and (ss[x,y-1]>0) then begin ss[x,y-1]:=0;lin(x,y-1);end;
    if (y>1) and (x>1) and (ss[x-1,y-1]>0) then begin ss[x-1,y-1]:=0;lin(x-1,y-1);end;
    if (x>1) and (ss[x-1,y]>0) then begin ss[x-1,y]:=0;lin(x-1,y);end;
    if (x>1) and (y<n) and (ss[x-1,y+1]>0) then begin ss[x-1,y+1]:=0;lin(x-1,y+1);end;
    if (y<n) and (ss[x,y+1]>0) then begin ss[x,y+1]:=0;lin(x,y+1);end;
    if (y<n) and (x<m) and (ss[x+1,y+1]>0) then begin ss[x+1,y+1]:=0;lin(x+1,y+1);end;
    if (x<m) and (ss[x+1,y]>0) then begin ss[x+1,y]:=0;lin(x+1,y);end;
    if (x<m) and (y>1) and (ss[x+1,y-1]>0) then begin ss[x+1,y-1]:=0;lin(x+1,y-1);end;
    end;
end;
//-----------------------------------------------------------------------
begin
assign(input,'badgras.in');
reset(input);
assign(output,'badgras.out');
rewrite(output);
read(m,n);
for a:=1 to m do
for b:=1 to n do
read(ss[a,b]);
for a:=1 to m do
for b:=1 to n do
if ss[a,b]>0 then
   begin
   inc(c);
   flood(a,b);
   end;
write(c);
close(input);
close(output);
end.