讨论 / Whyyy???????????????------------4
tdw 2013-08-17 17:44:00
点我顶贴 收藏 删除
各位大牛帮帮看看 第四点.......................

{o是原地图,u是判重,q是BFS队,f是第几步}

program migong;

var i,j,n,m,head,tail:longint;

o:array[0..21,0..21]of boolean;

u:array[0..21,0..21]of boolean;

q:array[1..2,1..400]of longint;

f:array[1..400]of longint;

x,y:integer;

ch:char;

begin

fillchar(o,sizeof(o),false);

fillchar(u,sizeof(u),false);

readln(n,m);

for i:=1 to n do

begin

for j:=1 to m do

begin

read(ch);

if ch='0' then o[i,j]:=true;

end;

readln;

end;

read(q[1,1],q[2,1]);

u[q[1,1],q[2,1]]:=true;

read(x,y);

o[x,y]:=true;

head:=1;

tail:=1;

repeat

i:=q[1,head];

j:=q[2,head];

if o[i+1,j] then begin inc(tail);q[1,tail]:=i+1;q[2,tail]:=j;f[tail]:=f[head]+1;if (q[1,tail]=x)and(q[2,tail]=y) then begin write(f[tail]);halt;end;if u[q[1,tail],q[2,tail]] then dec(tail) else u[q[1,tail],q[2,tail]]:=true;end;

if o[i-1,j] then begin inc(tail);q[1,tail]:=i-1;q[2,tail]:=j;f[tail]:=f[head]+1;if (q[1,tail]=x)and(q[2,tail]=y) then begin write(f[tail]);halt;end;if u[q[1,tail],q[2,tail]] then dec(tail) else u[q[1,tail],q[2,tail]]:=true;end;

if o[i,j-1] then begin inc(tail);q[1,tail]:=i;q[2,tail]:=j-1;f[tail]:=f[head]+1;if (q[1,tail]=x)and(q[2,tail]=y) then begin write(f[tail]);halt;end;if u[q[1,tail],q[2,tail]] then dec(tail) else u[q[1,tail],q[2,tail]]:=true;end;

if o[i,j+1] then begin inc(tail);q[1,tail]:=i;q[2,tail]:=j+1;f[tail]:=f[head]+1;if (q[1,tail]=x)and(q[2,tail]=y) then begin write(f[tail]);halt;end;if u[q[1,tail],q[2,tail]] then dec(tail) else u[q[1,tail],q[2,tail]]:=true;end;

inc(head);

until head>tail;

writeln('No Answer!');

end.

#1 li49406@2013-08-17 03:15:00
回复 删除
虽然不清楚错误原因(检查代码太麻烦)

这是我运行你程序的结果:

4 4

0 0 0 0

1 1 1 0

0 0 1 0

0 0 0 0

1 1

3 2

No Answer!

#2 xtc820@2013-08-17 05:50:00
回复 删除
dui

duile

#3 tdw@2013-08-17 17:44:00
回复 删除
多谢,是读入的时候,只读了(ch),把空格也算上(竟然也过9组),还有,数组开太小了...........
查看更多回复
提交回复