比赛 暑假培训B班二测 评测结果 AAAAAAEA
题目名称 劣质的草 最终得分 87
用户昵称 如烟 运行时间 0.136 s
代码语言 Pascal 内存使用 3.99 MiB
提交时间 2012-07-22 11:23:19
显示代码纯文本
type
 integer=longint;
const
   t:array[1..8,1..2] of integer=((-1,0),(0,-1),(1,0),(0,1),
                                  (1,-1),(-1,-1),(-1,1),(1,1));
var
  i,j,n,m,c,q:integer;
  a:array[0..1001,0..1001] of integer;
procedure try(k,x,y,new:integer);
var
   i:integer;
begin
 for i:=1 to 8 do
  if (x+t[i,1]>0)and(x+t[i,1]<=c)and
     (y+t[i,2]>0)and(y+t[i,2]<=n) and
     (a[x+t[i,1],y+t[i,2]]>0)and
     (a[x+t[i,1],y+t[i,2]]<>new)  then
  begin
   a[x+t[i,1],y+t[i,2]]:=new;
   try(k+1,x+t[i,1],y+t[i,2],new);
  end;
end;
begin
 assign(input,'badgras.in');
 reset(input);
 assign(output,'badgras.out');
 rewrite(output);
 read(c,n);
 m:=0;
 for i:=1 to c do
  for j:=1 to n do
   begin
   read(a[i,j]);
   if a[i,j]>m then m:=a[i,j];
   end;
  q:=m;
 for i:=1 to c do
  for j:=1 to n do
   if (a[i,j]>0) and (a[i,j]<=q) then
   begin
   m:=m+1;
   a[i,j]:=m;
   try(1,i,j,m);
   end;
write(m-q);
close(input);
close(output);
end.