Skip to content

Commit

Permalink
Merge pull request #126 from IJS1016/main
Browse files Browse the repository at this point in the history
임정선 24.3.2W ps
  • Loading branch information
IJS1016 authored Mar 18, 2024
2 parents 6606024 + 97bc31c commit 08a9742
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions 정선/python/baekjoon/14503_로봇청소기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# 빈칸이 없으면 후진, 벽에 부딪히면 작동 끝
# 있으면 반시계로 90도 회전 후 앞이 청소되지 않았으면 전진
# d : 0 상, 1 우, 2 하, 3 좌 (반시계 90도 회전 -> -1 % 4)
# 벽이랑 청소되지 않은거랑 다름, 청소된건 2로 나타내기

N, M = map(int, input().split())
r, c, d = map(int, input().split()) # r이 c, c가 r
mmap = []
for _ in range(N) :
mmap.append(list(map(int, input().split())))

directions = [[-1, 0], [0, 1], [1, 0], [0, -1]] # 상, 우, 하, 좌
result = 0

while (0 <= r < N and 0 <= c < M) : # 벽에 부딪히지 않은 경우
empty_flag = False
if mmap[r][c] == 0 :
mmap[r][c] = 2
result += 1

for dr, dc in directions :
if mmap[r+dr][c+dc] == 0 :
empty_flag = True
break

if empty_flag :
d = (d-1) % 4
dr, dc = directions[d]
if mmap[r+dr][c+dc] == 0 :
r+=dr
c+=dc
else :
dr, dc = directions[d]
r-=dr
c-=dc
if mmap[r][c] == 1 :
break

print(result)


0 comments on commit 08a9742

Please sign in to comment.