问题标题: 酷町堂中的1257为什么我样例过不了

0
0
已解决
程思怡
程思怡
中级守护
中级守护
const 
    map:array[0..8,0..8] of longint=(
    (1,1,1,1,1,1,1,1,1),
    (1,0,0,1,0,0,1,0,1),
    (1,0,0,1,1,0,0,0,1),
    (1,0,0,1,1,0,0,0,1),
    (1,0,0,1,1,0,0,0,1),
    (1,0,0,1,1,0,0,0,1),
    (1,1,0,1,0,1,0,0,1),
    (1,1,0,1,0,0,0,0,1),
    (1,1,1,1,1,1,1,1,1)
    );
    dir:array[1..4,1..2] of longint=(
        (-1,0),(1,0),(0,-1),(0,1)
    );
var 
    n,i,count,a,b,c,d:longint;
    used:array[0..8,0..8] of boolean;

procedure dfs(x,y,step:longint);
var nx,ny,i:longint;
begin 
    if (x=c) and (y=d) then 
    begin
        if step<count then count:=step;
        exit;
    end;
    for i:=1 to 4 do 
    begin 
        nx:=x+dir[i,1];
        ny:=y+dir[i,2];
        if (nx>=0) and (nx<=8) and (ny>=0) and (ny<=8)
        and (not used[nx,ny]) 
        and (map[nx,ny]=0) then 
        begin
            used[nx,ny]:=true;
            dfs(nx,ny,step+1);
            used[nx,ny]:=false;
        end;
    end;
end;

begin
    readln(n);
    for i:=1 to n do 
    begin 
        count:=10000000;
        fillchar(used,sizeof(used),false);
        readln(a,b,c,d);
        used[a,b]:=true;
        dfs(a,b,0);
        writeln(count);
    end;
end.

 


1
已采纳
叶卓舒
叶卓舒
初级守护
初级守护

迷宫输入错了,应该是:

1,1,1,1,1,1,1,1,1

1,0,0,1,0,0,1,0,1

1,0,0,1,1,0,0,0,1

1,0,1,0,1,1,0,1,1

1,0,0,0,0,1,0,0,1

1,1,0,1,0,1,0,0,1

1,1,0,1,0,1,0,0,1

1,1,0,1,0,0,0,0,1

1,1,1,1,1,1,1,1,1

0
0
0
我要回答