| 比赛 | 暑假培训B班二测 | 评测结果 | AAAAAAAA | 
    | 题目名称 | 劣质的草 | 最终得分 | 100 | 
    | 用户昵称 | hjr1995 | 运行时间 | 0.126 s | 
    | 代码语言 | Pascal | 内存使用 | 3.99 MiB | 
    | 提交时间 | 2012-07-22 11:11:26 | 
显示代码纯文本
var
c,r,i,j,s:longint;
a:array[0..1001,0..1001] of longint;
procedure dfs(x,y:longint);
begin
  if a[x,y]<>-1 then
    begin
    a[x,y]:=-1;
    if a[x+1,y]<>0 then dfs(x+1,y);
    if a[x-1,y]<>0 then dfs(x-1,y);
    if a[x,y+1]<>0 then dfs(x,y+1);
    if a[x,y-1]<>0 then dfs(x,y-1);
    if a[x+1,y+1]<>0 then dfs(x+1,y+1);
    if a[x-1,y+1]<>0 then dfs(x-1,y+1);
    if a[x+1,y-1]<>0 then dfs(x+1,y-1);
    if a[x-1,y-1]<>0 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); s:=0;
  readln(r,c);
  for j:=1 to r do
    begin
    for i:=1 to c do
      read(a[i,j]);
    readln;
    end;
  for i:=1 to c do
    for j:=1 to r do
      if (a[i,j]<>0) and (a[i,j]<>-1) then
        begin
        dfs(i,j);
        inc(s);
        end;
  writeln(s);
  close(input);close(output);
end.