Skip to content

Conversation

@rxdcxdrnine
Copy link
Contributor

안녕하세요, 배열 돌리기 1 문제 풀이를 들고온 Miller 입니다 😀
제가 낸 문제인만큼 주중에 계속 고민했는데, 결국 늦게 정답을 봤습니다 ㅠㅠ

아래 블로그를 참고했습니다.
https://dkanxmstmdgml.tistory.com/731

그리고 내부 회전 로직을 주석과 함께 정리해봤습니다.

# cnt : 바깥쪽부터 안쪽으로 몇번째 직사각형인지

# m_max : 해당 직사각형의 좌우 길이 - 1
# -> 위쪽/아래쪽 변 밀어내기 순회 시 cnt ~ m_max 까지 순회
m_max = (m - 1) - cnt

# n_max : 해당 직사각형의 상하 길이 - 1
# -> 왼쪽/오른쪽 변 밀어내기 순회 시 cnt ~ n_max 까지 순회
n_max = (n - 1) - cnt 

# 밀어내기 전에 시작점을 변수 tmp 에 저장
tmp: int = arr[cnt][cnt]

# 위쪽 변
for i in range(cnt, m_max):
    arr[cnt][i] = arr[cnt][i + 1]

# 오른쪽 변
for i in range(cnt, n_max):
    arr[i][m_max] = arr[i + 1][m_max]

# 아래쪽 변
for i in range(m_max, cnt, -1):
    arr[n_max][i] = arr[n_max][i - 1]

# 왼쪽 변
for i in range(n_max, cnt, -1):
    arr[i][cnt] = arr[i - 1][cnt]

# 밀어내기 후에 변수 tmo를 시작점 바로 아래에 할당
arr[cnt + 1][cnt] = tmp

생각하기 어려운 문제였는데, 앞으로 비슷한 문제를 만났을 때 어떻게 접근해야할지
조금씩 보이는 것 같습니다.

@rxdcxdrnine rxdcxdrnine self-assigned this May 14, 2022
@rxdcxdrnine rxdcxdrnine linked an issue May 14, 2022 that may be closed by this pull request
@rxdcxdrnine rxdcxdrnine merged commit f7d1cb5 into CodeSquad-Algorithm:main May 17, 2022
@rxdcxdrnine rxdcxdrnine deleted the BOJ_16926 branch May 18, 2022 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2022.05.10(화)] BOJ(16926) : 배열 돌리기 1

1 participant