Post

[BOJ] 1074. Z(python)

๐Ÿ“Œ๋ฌธ์ œ

Alt text Alt text

๐Ÿ’ช์•„์ด๋””์–ด

  1. ๋ฒ”์œ„ ๋‚˜๋ˆ„๊ธฐ
    1, 2, 3, 4์‚ฌ๋ถ„๋ฉด์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค.
    ํ–‰๊ณผ ์—ด์„ 2**(n-1)๋กœ ๋‚˜๋ˆˆ๊ฐ’์œผ๋กœ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋‚˜๋ˆ ์ค€๋‹ค.
    • 1์‚ฌ๋ถ„๋ฉด:(0,1)
    • 2์‚ฌ๋ถ„๋ฉด:(0,0)
    • 3์‚ฌ๋ถ„๋ฉด:(1,0)
    • 4์‚ฌ๋ถ„๋ฉด:(1,1)
  2. ์‚ฌ๋ถ„๋ฉด์—์„œ ์‹œ์ž‘๊ฐ’ ๊ตฌํ•˜๊ธฐ
  3. 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.