Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

[2023-08-18] sumin #113 #133

Merged
merged 2 commits into from
Aug 18, 2023
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
36 changes: 36 additions & 0 deletions BOJ/Z/sumin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
풀이시간: 25분

<input>
- 1 ≤ N ≤ 15
- 0 ≤ r, c < 2N

<solution>
1. 함수의 정의
- 2^n x 2^n 배열에서 (r,c)를 방문하는 순서를 반환하는 함수

2. base condition
- n = 0일 때, return 0

3. 재귀식
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

재귀식이 저랑 같은 것 같아요!! 수민님과 같은 식이 유도된 것 같아 성장한 기분이 듭니다 ㅎㅎ

- (r,c)가 1번 사각형일 때, return go(n-1, r, c)
- (r,c)가 2번 사각형일 때, return half*half + go(n-1, r, c-half)
- (r,c)가 3번 사각형일 때, return 2*half*half + go(n-1, r-half, c)
- (r,c)가 4번 사각형일 때, return 3*half*half + go(n-1, r-half, c-half)

"""
def go(n, r, c):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go가 뭔가 힘이나고 좋은 함수명인 것 같아서 웃고 갑니다 ㅎㅎ

if n == 0:
return 0
half = 2 ** (n-1)
if r < half and c < half: # 1번 사각형
return go(n-1, r, c)
elif r < half and c >= half: # 2번 사각형
return half * half + go(n-1, r, c-half)
elif r >= half and c < half: # 3번 사각형
return 2 * half * half + go(n-1, r-1, c)
return 3 * half * half + go(n-1, r-half, c-half) # 4번 사각형


n, r, c = map(int, input().split())
print(go(n, r, c))