[BOJ] 1074. Z(python)
๐๋ฌธ์
๐ช์์ด๋์ด
- ๋ฒ์ ๋๋๊ธฐ
1, 2, 3, 4์ฌ๋ถ๋ฉด์ผ๋ก ๋๋๋ค.
ํ๊ณผ ์ด์ 2**(n-1)๋ก ๋๋๊ฐ์ผ๋ก ๊ฒฝ์ฐ์ ์๋ฅผ ๋๋ ์ค๋ค.- 1์ฌ๋ถ๋ฉด:(0,1)
- 2์ฌ๋ถ๋ฉด:(0,0)
- 3์ฌ๋ถ๋ฉด:(1,0)
- 4์ฌ๋ถ๋ฉด:(1,1)
- 1์ฌ๋ถ๋ฉด:(0,1)
- ์ฌ๋ถ๋ฉด์์ ์์๊ฐ ๊ตฌํ๊ธฐ
- x,y๊ฐ ์กฐ์ ํ๊ธฐ
๐ฅ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys
input = sys.stdin.readline
n,r,c = map(int,input().split())
answer = 0
while n:
n -= 1
group = (r//(2**n),c//(2**n))
if group == (0,0): #2์ฌ๋ถ๋ฉด
d = 0
elif group == (0,1): #1์ฌ๋ถ๋ฉด
d = 1
c -= 2**n
elif group == (1,0): #3์ฌ๋ถ๋ฉด
d = 2
r -= 2**n
else: #4์ฌ๋ถ๋ฉด
d = 3
r -= 2**n
c -= 2**n
answer += (2**n)*(2**n)*d
print(answer)
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.