首页| 论坛| 消息
主题:高手请进!
zyq2ns发表于 2008-10-23 00:37
有个问题要讨论一下,8数码问题,但是运行就是出201错。讨论一下错在哪里...
在运行到最后的时候,p1=-1,tail=5,st=1时,光标过了条件式
if (p1 in [1..9]) and not ((p0=3) and (p1=4))and not((p0=4)and (p1=3))
and not((p0=6)and(p1=7))and not((p0=7)and(p1=6))
源程序如下:
program num8;
const maxn=4000;
type jid=record
str:string[9];
f:0..maxn;
dep:byte;
end;
bin=0..1;
var c:array[0..1,1..maxn] of ^jid;
head,tail:array[0..1] of integer;
start,goal:string[9];
procedure init;
var i,j:integer;
begin
start:='283164705';
goal:='123804765';
for i:=0 to 1 do
for j:=1 to maxn do
new(c);
c[0,1]^.str:=start; c[0,1]^.f:=0; c[0,1]^.dep:=0;
c[1,1]^.str:=goal; c[1,1]^.f:=0; c[1,1]^.dep:=0;
for i:=0 to 1 do
begin head:=0;tail:=1;end;
end;
procedure print(st:bin;tail,k:integer);
procedure print0(m:integer);
begin
if m0 then
begin print0(c[0,m]^.f);writeln(c[0,m]^.str) end;
end;
procedure print1(m:integer);
var n:integer;
begin
n:=c[1,m]^.f;
while n0 do
begin writeln(c[1,n]^.str); n:=c[1,n]^.f end;
end;
begin
if st=0 then
begin writeln('step=',c[0,tail]^.dep+c[1,k]^.dep);
print0(tail); print1(k);end
else begin writeln('step=',c[0,k]^.dep+c[1,tail]^.dep);
print0(k); print1(tail); end ;
halt;
end;
procedure check(st:bin);
procedure bool(st:bin);
var i:integer;
begin
for i:=1 to tail[1-st] do
if c]^.str=c[1-st,i]^.str then print(st,tail,i);
end;
var i:integer;
begin
for i:=1 to tail-1 do
if c]^.str=c^.str then
begin dec(tail);exit end;
bool(st);
end;
procedure expand(st:bin);
var i,p0,p1,d:integer;
str0,str1:string[9];
begin
inc(head)
下一页 (1/3)
回帖(3):
3楼:201一般是指数组开小了。。。。你看看调用数组的下标是否在数组 ..
2楼:过了那个条件式,就出201运行错了...问题在哪?
1楼:双向广搜

--> 全部回帖(3)»
最新回帖
收藏本帖
发新帖