比赛 NOIP2008集训模拟4 评测结果 WAWAWWWTTWTTT
题目名称 潜入辛迪加 最终得分 15
用户昵称 E.M.B.E.R 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 10:03:51
显示代码纯文本
program EmberAsh;
const
  dx:array[1..4]of integer=(0,-1,1,0);
  dy:array[1..4]of integer=(-1,0,0,1);
var
a:array[0..50,0..50]of longint;
f:array[0..50,0..50]of longint;//记忆化
b:array[1..16]of boolean;//供电装置
step:array[0..50,0..50]of boolean;
i,j,k,n,m,ii:longint;
fin,fout:text;

procedure try(x,y,s:longint);
var
i,j,k,x1,y1,s1:longint;
begin
for i:=1 to 4 do
  begin
  x1:=x+dx[i];y1:=y+dy[i];s1:=s+1;
  if (x1>=0)and(x1<=n)and(y1>=0)and(y1<=n) then
    if(a[x1,y1]<>-1)and(a[x1,y1]<>-2) then//不是障碍物或卫兵叔叔- -
      begin
      //if (a[x1,y1]>=1)and(a[x1,y1]<=m)and(step[x1,y1]=false) then//违规建筑(供电装置) 拆~
        //begin
        //b[i]:=true;//不是我拆的 是城管拆的(- =)
        //step[x1,y1]:=true;
        //f[x1,y1]:=s1;
        //try(x1,y1,s1);
        //b[i]:=false;
        //step[x1,y1]:=false;
        //end;
      //if (a[x1,y1]>m)and(b[i-m]=true)and(step[x1,y1]=false) then//电磁监视器被城管拆了...
        //begin
        //f[x1,y1]:=s1;
        //step[x1,y1]:=true;
        //try(x1,y1,s1);
        //step[x1,y1]:=false;
        //end;
      if (a[x1,y1]=0)and(step[x1,y1]=false) then
        begin
        f[x1,y1]:=s1;
        step[x1,y1]:=true;
        try(x1,y1,s1);
        step[x1,y1]:=false;
        end;
    end;//if
  end;//for
end;//procedure

BEGIN
assign(fin,'syndicate.in');reset(fin);
assign(fout,'syndicate.out');rewrite(fout);
readln(fin,n,m);
for i:=1 to n do
  for j:=1 to n do
    begin
    read(fin,a[i,j]);
    f[i,j]:=maxlongint;
    //if (a[i,j]>=1)and(a[i,j]<=m) then
     // if a[i,j]>ii then ii:=a[i,j];//最大供电装置的数量
    if a[i,j]=-2 then//卫兵
      begin
      a[i,j-1]:=-2;
      a[i-1,j]:=-2;
      a[i+1,j]:=-2;
      a[i,j+1]:=-2;
      end;
    end;
try(1,1,0);
writeln(fout,f[n,n]);
close(fin);close(fout);
END.