记录编号 41354 评测结果 AAAAAAAA
题目名称 劣质的草 最终得分 100
用户昵称 GravatarFangel 是否通过 通过
代码语言 Pascal 运行时间 0.142 s
提交时间 2012-07-22 11:50:17 内存使用 11.61 MiB
显示代码纯文本
var
a,b,c,d,m,n,i,j:longint;
ss:array[1..1000,1..1000] of longint;
line:array[0..999999,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.