比赛 暑假培训B班二测 评测结果 AAAAAAEA
题目名称 劣质的草 最终得分 87
用户昵称 digital-T 运行时间 0.069 s
代码语言 Pascal 内存使用 3.99 MiB
提交时间 2012-07-22 09:55:48
显示代码纯文本
var
r,c,i,j,k,fresh:longint;
f:array[0..1001,0..1001]of longint;
procedure dfs(a,b:longint);
begin
f[a,b]:=fresh;
if f[a+1,b]=0 then dfs(a+1,b);
if f[a-1,b]=0 then dfs(a-1,b);
if f[a,b+1]=0 then dfs(a,b+1);
if f[a,b-1]=0 then dfs(a,b-1);
if f[a+1,b-1]=0 then dfs(a+1,b-1);
if f[a-1,b+1]=0 then dfs(a-1,b+1);
if f[a+1,b+1]=0 then dfs(a+1,b+1);
if f[a-1,b-1]=0 then dfs(a-1,b-1);
end;

begin
assign(input,'badgras.in');reset(input);
assign(output,'badgras.out');rewrite(output);
k:=0;
fresh:=0;
read(r,c);
for i:=1 to r do
 for j:=1 to c do
  begin
   read(f[i,j]);
   if f[i,j]=0 then f[i,j]:=-1;
   if f[i,j]>0 then f[i,j]:=0;
  end;


for i:=0 to r do f[i,0]:=-1;
for j:=0 to c do f[0,j]:=-1;
for i:=0 to r do f[i,c+1]:=-1;
for j:=0 to c do f[r+1,j]:=-1;

for i:=1 to r do
 for j:=1 to c do
  if f[i,j]=0 then
   begin
    inc(k);
    inc(fresh);
    dfs(i,j);
   end;
write(fresh);

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