ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

๐Ÿšฉ ๋ถ„ํ• ์ •๋ณต, ์žฌ๊ท€ํ•จ์ˆ˜

 

thinking

์ฒ˜์Œ์— 4๋ถ€๋ถ„์œผ๋กœ ์ชผ๊ฐœ๊ณ  ์นด์šดํŒ…ํ–ˆ๋Š”๋ฐ output์€ ๋งž๊ฒŒ ๋‚˜์™”์œผ๋‚˜ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋–ด๋‹ค.

์‹œ๊ฐ„์ดˆ๊ณผ๋ฅผ ์ค„์ด๊ณ ์ž ๋งˆ์ง€๋ง‰ else๋ฌธ์˜ ๋ฒ”์œ„๋ฅผ ๋‚˜๋ˆด๋”๋‹ˆ ํŒจ์“ฐ๋๋‹ค..

 

์ฝ”๋“œ (pass)

def divide(s_x, s_y, N):
    global cnt
    if N == 2:
        if s_x == r and s_y == c:  # 1์œ„์น˜
            print(cnt)
            return
        if s_x == r and s_y+1 == c:  # 2์œ„์น˜
            cnt += 1
            print(cnt)
            return
        if s_x+1 == r and s_y == c:  # 3์œ„์น˜
            cnt += 2
            print(cnt)
            return
        if s_x+1 == r and s_y+1 == c:  # 4์œ„์น˜
            cnt += 3
            print(cnt)
            return
        else:
            cnt += 4
            return
    else:
        half = N // 2
        if s_x <= r < s_x + half and s_y <= c < s_y + half:  # 1์‚ฌ๋ถ„๋ฉด
            divide(s_x, s_y, half)
        elif s_x <= r < s_x + half and s_y + half <= c < s_y + 2*half:  # 2์‚ฌ๋ถ„๋ฉด
            cnt += half*half
            divide(s_x, s_y + half, half)
        elif s_x + half <= r < s_x + 2*half and s_y <= c < s_y + half:  # 3์‚ฌ๋ถ„๋ฉด
            cnt += half*half*2
            divide(s_x + half, s_y, half)
        elif s_x + half <= r < s_x + 2*half and s_y + half <= c < s_y + 2*half:  # 4์‚ฌ๋ถ„๋ฉด
            cnt += half*half*3
            divide(s_x + half, s_y + half, half)


N, r, c = map(int, input().split())

cnt = 0
divide(0,0,2**N)

 

์‹œ๊ฐ„์ดˆ๊ณผ ๋‚œ ์ฝ”๋“œ (fail)

def divide(s_x, s_y, N):
    global cnt
    if N == 2:
        if s_x == r and s_y == c:  # 1์œ„์น˜
            print(cnt)
            return
        if s_x == r and s_y+1 == c:  # 2์œ„์น˜
            cnt += 1
            print(cnt)
            return
        if s_x+1 == r and s_y == c:  # 3์œ„์น˜
            cnt += 2
            print(cnt)
            return
        if s_x+1 == r and s_y+1 == c:  # 4์œ„์น˜
            cnt += 3
            print(cnt)
            return
        else:
            cnt += 4
            return
    else:
        divide(s_x, s_y, N // 2)
        divide(s_x, s_y + N // 2, N // 2)
        divide(s_x + N // 2, s_y, N // 2)
        divide(s_x + N // 2, s_y + N // 2, N // 2)


N, r, c = map(int, input().split())

cnt = 0
divide(0,0,2**N)

 

 

ํ•œ์ค„ํ›„๊ธฐ

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ๋ผ๊ธฐ๋ณด๋‹ค ์ˆ˜ํ•™๋ฌธ์ œ ๊ฐ™์•˜๋˜.. ๋…ธ๊ฐ€๋‹ค์˜ ํ–ฅ์—ฐ์ด์—ˆ์Œ

๋Œ“๊ธ€