09_kontrola - ocena 10

This commit is contained in:
Gašper Dobrovoljc 2023-12-27 18:23:19 +01:00
parent 3b7295f5c6
commit 7652318932
No known key found for this signature in database
GPG Key ID: 0E7E037018CFA5A5

View File

@ -23,7 +23,7 @@ def check(x: int, y: int, c: str, zemljevid: list[str], prepovedani: set = None)
)
def najblizji_distance(x: int, y: int, c: str, zemljevid: list[str], prepovedani: set):
def najblizji_distance(x: int, y: int, c: str, zemljevid: list[str], prepovedani: set = None):
d = 1
max_d = len(zemljevid) + len(zemljevid[0])
@ -152,3 +152,41 @@ def najboljsa_cetrt(a: int, zemljevid: list[str]):
max_y = y
return max_x, max_y
def dosegljive(x, y, max_d, max_n, zemljevid):
def dosegljive_r(x, y, n, prepovedani):
if zemljevid[y][x] == "*":
n = max_n
else:
if n == 0:
return set()
prepovedani.add((x, y))
points = set()
accessible = set()
for d in range(1, max_d + 1):
x -= 1
ry = 0
ry_inc = 1
for rx in range(d * 2 + 1):
xx = x + rx
y1 = y - ry
y2 = y + ry
if check(xx, y1, "", zemljevid, prepovedani) and (zemljevid[y1][xx] != "*" or n < max_n):
accessible.add((xx, y1))
if check(xx, y2, "", zemljevid, prepovedani) and (zemljevid[y2][xx] != "*" or n < max_n):
accessible.add((xx, y2))
if ry == d:
ry_inc = -1
ry += ry_inc
points.update(accessible)
for x, y in accessible:
points.update(dosegljive_r(x, y, n - 1, prepovedani))
return points
tocke = dosegljive_r(x, y, max_n, set())
return {(x, y) for x, y in tocke if zemljevid[y][x] != "*"}