# 迷宫

114人阅读 评论(0)

program migong;
type node=record
xx,yy:longint;
end;
all=array[1..10,1..10]of longint;
const n=400;
dx:array[1..4]of longint=(0,1,0,-1);
dy:array[1..4]of longint=(1,0,-1,0);
a:all=((0,0,0,0,0,0,1,0,1,1),
(0,1,0,1,1,0,0,0,0,0),
(0,1,0,1,1,0,1,1,1,0),
(0,1,0,0,0,0,0,1,0,0),
(0,1,1,1,1,1,1,1,1,1),
(0,0,0,1,0,1,0,0,0,0),
(0,1,1,1,0,0,0,1,1,1),
(0,0,0,0,0,1,0,0,0,0),
(1,1,0,1,1,1,0,1,1,0),
(1,1,1,1,1,1,0,1,1,1));
state:array[1..n]of node;
father:array[1..n]of longint;
function check:boolean;
begin
check:=false;
if (nx<1)or(nx>10)or(ny<1)or(ny>10) then
check:=false
else if a[ny,nx]=1 then check:=false
else check:=true;
end;
function dupe:boolean;
var i,j:longint;buf:boolean;
begin
buf:=false;i:=0;
repeat
inc(i);
if (state[i].xx=state[tail].xx)and(state[i].yy=state[tail].yy)then
buf:=true else buf:=false
until buf or(i>=tail-1);
dupe:=buf;
end;
procedure print;
var buf:array[1..n]of longint;
i,j,m:longint;
begin
m:=1;j:=tail;buf[1]:=j;
while j>0 do
begin
j:=father[j];
inc(m);buf[m]:=j;
end;
for i:=m-1 downto 2 do
write('(',state[buf[i]].xx,',',state[buf[i]].yy,')','--');
writeln('(',state[buf[1]].xx,',',state[buf[1]].yy,')');
halt;
end;
begin
x1:=8;y1:=1;x2:=7;y2:=10;
state[1].xx:=x1;
state[1].yy:=y1;
repeat
for k:=1 to 4 do
if check then
begin
inc(tail);
state[tail].xx:=nx;
state[tail].yy:=ny;
if dupe then dec(tail)
else if (state[tail].xx=x2)and(state[tail].yy=y2)
then print;
end;
end.
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：14875次
• 积分：106
• 等级：
• 排名：千里之外
• 原创：91篇
• 转载：0篇
• 译文：0篇
• 评论：0条
文章分类
文章存档
评论排行