Pagini recente » Cod sursa (job #676357) | Cod sursa (job #2156055) | Cod sursa (job #2202409) | Cod sursa (job #761935) | Cod sursa (job #79022)
Cod sursa(job #79022)
CONST ax : Array[1..8] of integer = (-1,1,1,0,-1,0,1,-1);
ay : Array[1..8] of integer = (-1,1,0,1,0,-1,-1,1);
Type nod = RECORD
x,y:0..127;
End;
coada = RECORD
q:array[0..10000] of nod;
sP,eP:Integer;
End;
matrice = array[0..100,0..100] of 0..1;
Var
a:matrice;
q:coada;
b:array[0..100,0..100] of Integer;
n:integer;
Procedure citeste;
var i,j:integer;
Begin
Assign(input,'date.in');
Reset(input);
ReadLN(n);
For i:=1 to n do
For j:=1 to n do
Read(a[i][j]);
End;
Procedure rezolva;
Var
unnod:nod;
i,j:Integer;
Begin
q.sp:=0;
q.ep:=1;
q.q[1].x:=1;
q.q[1].y:=1;
For i:=1 to n do
For j:=1 to n do
IF a[i][j]=0 then b[i][j]:=0
else b[i][j]:=10000;
for i:=0 to n+1 do
begin
b[i][0]:=-1;
b[i][n+1]:=-1;
b[n+1][i]:=-1;
b[0][i]:=-1;
end;
b[1][1]:=1;
While q.sP<>q.ep do
Begin
inc(q.sp);
unnod:=q.q[q.sp];
For i:=1 to 8 do
If b[unnod.x+ax[i]][unnod.y+ay[i]]=0 then
Begin
b[unnod.x+ax[i]][unnod.y+ay[i]]:=b[unnod.x][unnod.y]+1;
inc(q.ep);
q.q[q.ep].x:=unnod.x+ax[i];
q.q[q.ep].y:=unnod.y+ay[i];
End;
End;
End;
Procedure afis;
var i,j : integer;
Begin
assign(output,'rj.out');
rewrite(output);
For i:=1 to n do
begin
For j:=1 to n do
if(b[i][j] <> 10000)then
write(b[i][j], ' ')
else
write('x ');
writeln;
end;
flush(output);
End;
Begin
citeste;
rezolva;
afis;
End.