728x90
반응형
Python - 왼쪽 아래 start부분이 잘못되어 헤맸다
n, r, c = map(int, input().split())
start = 0
end = (2 ** n) * (2 ** n) - 1
length = 2 ** n#length는 가로 세로 크기 -> ex 8줄
#ex 2 2 2 -> 4줄, 2행 2열(0부터 시작)
while True:
nextLength = length // 2
if start == end:
print(start)
break
#왼쪽 위일 때
if r < nextLength and c < nextLength:
end = start + nextLength ** 2 -1
#오른쪽 위일 때
elif r < nextLength and c >= nextLength:
start = start + nextLength ** 2
end = start + nextLength ** 2 - 1
#왼쪽 아래일 때
elif r >= nextLength and c < nextLength:
start = start + (nextLength ** 2) * 2
end = start + nextLength ** 2 - 1
#오른쪽 아래일 때
elif r >= nextLength and c >= nextLength:
start = end - nextLength ** 2 + 1
r = r % nextLength
c = c % nextLength
length = nextLength
728x90
반응형
'백준 알고리즘 > 실버' 카테고리의 다른 글
1058 친구 (0) | 2022.03.10 |
---|---|
1024 수열의 합 (0) | 2022.03.09 |
1012 유기농 배추 (0) | 2022.03.08 |
1105 팔 (0) | 2022.03.07 |
1080 행렬 (0) | 2022.03.06 |