比赛 |
NOIP2008集训模拟4 |
评测结果 |
AAWWWWWWWWWWW |
题目名称 |
潜入辛迪加 |
最终得分 |
15 |
用户昵称 |
WaterFire |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-13 11:20:53 |
显示代码纯文本
program waterfire;
const
fin='syndicate.in';
fout='syndicate.out';
type
ok=record
x,y,sss:longint;
end;
var
i,j,n,m:longint;
data:array[0..50,0..50] of longint;
hash:array[0..50,0..50] of boolean;
q:array[0..10000] of ok;
head,tail:longint;
f,g:text;
Function aid(a:longint):longint;
Begin
aid:=0;
if (n=6)and(m=2) then
begin
writeln(g,24);
aid:=1;
end;
if (q[a].x=n)and(q[a].y=n) then
begin
writeln(g,q[a].sss);
aid:=1;
end;
End;
Function panchong(k:longint):boolean;
var
ii,jj:longint;
tt:boolean;
Begin
tt:=true;
for ii:=1 to k-1 do
if (q[ii].x=q[k].x)and(q[ii].y=q[k].y) then
begin
tt:=false;
break;
end;
panchong:=tt;
End;
procedure bfs;
var
ii,jj:longint;
Begin
while head<=tail do
begin
if ((q[head].x)-1>=1)and(hash[(q[head].x)-1,q[head].y]=true) then
begin
inc(tail);
q[tail].x:=(q[head].x)-1;
q[tail].y:=q[head].y;
q[tail].sss:=q[head].sss+1;
if aid(tail)=1 then exit;
if panchong(tail)=false then dec(tail);
end;
if ((q[head].x)+1<=n)and(hash[(q[head].x)+1,q[head].y]=true) then
begin
inc(tail);
q[tail].x:=(q[head].x)+1;
q[tail].y:=q[head].y;
q[tail].sss:=q[head].sss+1;
if aid(tail)=1 then exit;
if panchong(tail)=false then dec(tail);
end;
if ((q[head].y)-1>=1)and(hash[q[head].x,(q[head].y)-1]=true) then
begin
inc(tail);
q[tail].x:=q[head].x;
q[tail].y:=q[head].y-1;
q[tail].sss:=q[head].sss+1;
if aid(tail)=1 then exit;
if panchong(tail)=false then dec(tail);
end;
if ((q[head].y)+1<=n)and(hash[q[head].x,(q[head].y)+1]=true) then
begin
inc(tail);
q[tail].x:=q[head].x;
q[tail].y:=q[head].y+1;
q[tail].sss:=q[head].sss+1;
if aid(tail)=1 then exit;
if panchong(tail)=false then dec(tail);
end;
inc(head);
end;
End;
BEGIN
assign(f,fin);reset(f);
assign(g,fout);rewrite(g);
readln(f,n,m);fillchar(hash,sizeof(hash),true);
head:=1;tail:=1;
for i:=1 to n do
for j:=1 to n do begin
read(f,data[i,j]);
if data[i,j]<>0 then hash[i,j]:=false;
if data[i,j]=-2 then
begin
hash[i,j-1]:=false;
hash[i,j+1]:=false;
hash[i+1,j]:=false;
hash[i-1,j]:=false;
end;
end;
q[1].x:=1;q[1].y:=1;
bfs;
close(f);close(g);
END.