TIL) 1074 Z

Mongleยท2020๋…„ 12์›” 17์ผ
0

Problem Solving and Algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
19/42

๐ŸŽƒ 4๋ถ„๋ฉด์œผ๋กœ ๋‚˜๋ˆ„๊ธฐ

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

  • ์ „์ฒด ์‚ฌ์ด์ฆˆ๊ฐ€ 2์˜ ์ œ๊ณฑ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ „์ฒด๋ฅผ 4๋ถ„๋ฉด์œผ๋กœ ๋‚˜๋ˆ ์„œ ํ•œ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ 2๊ฐ€ ๋ ๋•Œ๊นŒ์ง€ ๋‚˜๋ˆˆ๋‹ค.
  • ํ•œ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ 2๊ฐ€ ๋˜๋ฉด r๊ณผ c๋ฅผ ์ด์šฉํ•ด์„œ ์ˆซ์ž๋ฅผ ์ฐพ๋Š”๋‹ค.
  • ์ˆซ์ž๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ€์žฅ ์™ผ์ชฝ ๋งจ ์œ„์˜ ์ˆซ์ž์— ์ฃผ๋ชฉํ•ด์„œ ์žฌ๊ท€๋ฅผ ํ†ตํ•ด ์‚ฌ์ด์ฆˆ๊ฐ€ ์ž‘์•„์งˆ ๋•Œ๋งˆ๋‹ค idx๋ฅผ ์ด์šฉํ•ด์„œ ์‹œ์ž‘ํ•˜๋Š” ์ˆซ์ž๋ฅผ ์ง€์ •ํ•ด์ค˜์•ผํ•œ๋‹ค.
N, r, c = map(int, input().split())

def divide(size, r, c):
    idx = 0
    if size == 2:
        return r * 2 + c * 1
    half = size // 2
    if r < half and c < half:
        return idx + divide(half, r, c)
    elif r < half and c >= half:
        idx += int(size * size / 4)
        return idx + divide(half, r, c-half)
    elif r >= half and c < half:
        idx += int(size * size / 4 * 2)
        return idx + divide(half, r-half, c)
    else:
        idx += int(size * size / 4 * 3 )
        return idx + divide(half, r-half, c-half)

print(divide(2**N, r, c))
profile
https://github.com/Jeongseo21

0๊ฐœ์˜ ๋Œ“๊ธ€