백준 알고리즘/실버
1074 Z
GenieLove!
2022. 3. 4. 01:58
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
반응형