๐ฆ ์์ดํ ์ค๊ธฐ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
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
MAP = []
for i in range(51):
MAP.append([0] * 51)
def fill(rectangle): # ๋ชจ๋ ๋ฉด์ ์น ํจ
global MAP
for lx, ly, rx, ry in rectangle:
for x in range(lx, rx + 1):
for y in range(ly, ry + 1):
MAP[y][x] = 1
def stroke(rectangle): # ์ ์ ์ ์ธํ ๋ด๋ถ ๋ฉด์ ์ง์
global MAP
fill(rectangle)
for lx, ly, rx, ry in rectangle:
for x in range(lx + 1, rx):
for y in range(ly + 1, ry):
MAP[y][x] = 0
def solution(rectangle, characterX, characterY, itemX, itemY):
global MAP
stroke(rectangle)
delta = [
(0, 1), (0, -1), (1, 0), (-1, 0)
]
q = [(characterX, characterY, 0)]
while q:
cx, cy, count = q.pop(0)
if (cx, cy) == (itemX, itemY):
return count
# MAP[cy][cx] = 0
for dx, dy in delta:
nx = cx + dx
ny = cy + dy
if 1 <= nx <= 50 and 1 <= ny <= 50 and MAP[ny][nx] == 1:
MAP[ny][nx] = 0
q.append((nx, ny, count + 1))
return -1
- ์ ํ์ฑ
3. ํด์ค
This post is licensed under CC BY 4.0 by the author.