✅문제
✅문제 풀이
1. 현재 위치 청소
2. 청소가 이미 되어 있는경우
1) 방향 그대로 후진
2) 후진후 벽이면 작동을 멈춤
3. 청소가 안된 곳이 있는 경우
1) 반시계방향 90도 돌기
2) 앞 부분이 청소가 안되어 있으면 한칸 전진
1 , 2, 3 반복하여 도식화후 코딩
✅Code
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
n, m = map(int, input().split())
r, c, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
check = [[False]*m]*n
ans = 0
while True:
if a[r][c] == 0:
a[r][c] = 2
if a[r+1][c] != 0 and a[r][c+1] != 0 and a[r-1][c] != 0 and a[r][c-1] != 0:
nx, ny = c-dx[d], r-dy[d]
if a[ny][nx] == 1:
break
else:
c, r = nx, ny
else:
d = (d-1) % 4
nx, ny = c+dx[d], r+dy[d]
if a[ny][nx] == 0:
c, r = nx, ny
for i in range(n):
for j in range(m):
if a[i][j] == 2:
ans += 1
print(ans)
'알고리즘 > 구현' 카테고리의 다른 글
[백준] 4673번 : 셀프 넘버(python) (1) | 2023.10.26 |
---|---|
[백준] 14890번 : 경사 풀이(python) (0) | 2023.10.26 |
[백준] 15662번 : 톱니바퀴(2) 풀이(python) (1) | 2023.10.19 |
[백준] 14499번 : 주사위 굴리 풀이(python) (1) | 2023.10.19 |