-
Notifications
You must be signed in to change notification settings - Fork 0
/
BANGA.PAS
81 lines (73 loc) · 2 KB
/
BANGA.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{ MK 2001 }
{ bangos algoritmo demostracija }
program banga;
type
Tlab = array [1 .. 100, 1 .. 100] of shortint;
Tkelias = array [1 .. 10000, 1 .. 2] of shortint;
var
f : text;
c : char;
x1, y1,
x2, y2,
n, { labirinto dydis }
z,
ck,
ckx, cky : integer;
lab : Tlab;
kelias : Tkelias;
ats : array [1 .. 100, 1 .. 100] of 0 .. 1;
procedure zenk (zings : integer; var lab : Tlab; x, y : shortint);
begin
if (lab [x, y] = -1) or ((lab [x, y] < zings) and not (lab [x, y] = 0)) then exit
else begin
lab [x, y] := zings;
if x + 1 <= n then zenk (zings + 1, lab, x + 1, y);
if y + 1 <= n then zenk (zings + 1, lab, x, y + 1);
if x - 1 > 0 then zenk (zings + 1, lab, x - 1, y);
if y - 1 > 0 then zenk (zings + 1, lab, x, y - 1);
end;
end;
procedure atgal (zings : integer; const lab : Tlab; x, y : integer; var kelias : Tkelias);
begin
if (lab [x, y] >= zings) and (z <> zings) or (lab [x, y] = -1) or (zings = 0) then exit
else begin
kelias [zings, 1] := x;
kelias [zings, 2] := y;
if x + 1 <= n then atgal (zings - 1, lab, x + 1, y, kelias);
if y + 1 <= n then atgal (zings - 1, lab, x, y + 1, kelias);
if x - 1 > 0 then atgal (zings - 1, lab, x - 1, y, kelias);
if y - 1 > 0 then atgal (zings - 1, lab, x, y - 1, kelias);
end;
end;
begin
assign (f, 'bang.dat');
reset (f);
readln (f, n);
readln (f, x1, y1);
readln (f, x2, y2);
for cky := 1 to n do
begin
for ckx := 1 to n do
begin
read (f, c);
if c = '0' then lab [ckx, cky] := 0
else lab [ckx, cky] := -1
end;
readln (f);
end;
close (f);
zenk (0, lab, x1, y1);
z := lab [x2, y2];
atgal (z + 1, lab, x2, y2, kelias);
for ck := 2 to z + 1 do
ats [kelias [ck, 1], kelias [ck, 2]] := 1;
assign (f, 'bang.rez');
rewrite (f);
for cky := 1 to n do
begin
for ckx := 1 to n do
write (f, ats [ckx, cky] :2);
writeln (f);
end;
close (f);
end.