比赛 NOIP2008集训模拟4 评测结果 EEEEEEEEEEEEE
题目名称 潜入辛迪加 最终得分 0
用户昵称 elysian 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 11:25:26
显示代码纯文本
program elysian;
type
node=record
x,y:longint;
end;
const
fin='a.txt';fout='syndicate.out';
dx:array[1..4] of integer=(1,-1,0,0);
dy:array[1..4] of integer=(0,0,1,-1);
var
n,t,m:longint;
f:array[1..50,1..16] of boolean;
p:array[0..100000] of node;
a:array[0..100000,0..50,0..50] of integer;
f1,f2:text;
chong:boolean;

procedure init;
var
i,j,tx,ty,k:longint;
begin
assign(f1,fin);reset(f1);
readln(f1,n,m);
for i:=1 to n do
for j:=1 to n do
 begin
  if a[1,i,j]=0 then
  begin
  read(f1,a[1,i,j]);
   if a[1,i,j]=-2 then
   begin
    a[1,i,j]:=-1;
    for k:=1 to 4 do
     begin
     tx:=i+dx[k];ty:=j+dy[k];
     if (tx>0)and(tx<=n)and(ty>0)and(ty<=n) then
      a[1,tx,ty]:=-1;
     end;
    end;
  if a[1,i,j]>0 then a[1,i,j]:=-1;

  end;
end;
a[1,1,1]:=-3;
p[1].x:=1;
p[1].y:=1;
close(f1);
end;

procedure  rep(tail:longint);
var
i,j,k:longint;
flag:boolean;
begin
for i:=1 to tail-1 do
begin
flag:=false;
 for j:=1 to n do
  begin
    for k:=1 to n do
     if a[tail,j,k]<>a[i,j,k] then begin flag:=true;break;end;
  if flag=true then break;
  end;
if flag=false then begin chong:=true;exit;end;
end;
end;

procedure print;
begin
assign(f2,fout);rewrite(f2);
writeln(f2,t);
close(f2);
halt;
end;

procedure bfs;
var
head,tail,i,j,k,x1,y1:longint;
begin
head:=0;tail:=1;
repeat
inc(t);
inc(head);
 for i:=1 to 4 do
  x1:=p[head].x+dx[i];
  y1:=p[head].y+dy[i];
  if (x1=0)and(y1=0) then
    begin
    if (x1=n)and(y1=n) then begin print;end;
    inc(tail);
    a[tail]:=a[head];
    a[tail,x1,y1]:=-3;
    rep(tail);
    if chong then dec(tail);
    end;

until head>=tail;


end;


begin
init;
bfs;
end.