Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

임정선 24.3.2W ps #126

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)