ํฐ์คํ ๋ฆฌ ๋ทฐ
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)
ํ์คํ๊ธฐ
์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ๋ผ๊ธฐ๋ณด๋ค ์ํ๋ฌธ์ ๊ฐ์๋.. ๋ ธ๊ฐ๋ค์ ํฅ์ฐ์ด์์
'algorithm > baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 1012. ์ ๊ธฐ๋ ๋ฐฐ์ถ / python ํ์ด์ฌ (0) | 2021.04.08 |
---|---|
[๋ฐฑ์ค] 1003. ํผ๋ณด๋์น ํจ์ / python ํ์ด์ฌ (0) | 2021.04.08 |
[๋ฐฑ์ค] 2630. ์์ข ์ด ๋ง๋ค๊ธฐ / python ํ์ด์ฌ (0) | 2021.04.08 |
[๋ฐฑ์ค] 2164. ์นด๋2 / python ํ์ด์ฌ (0) | 2021.04.08 |
[๋ฐฑ์ค] 15649. N๊ณผ M (1) / python ํ์ด์ฌ (0) | 2021.04.08 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
TAG
- 2018 ์นด์นด์ค ๊ณต์ฑ
- merge ์๋ฌ
- ํ๋ก๊ทธ๋๋จธ์ค
- merge์๋ฌ
- 20057 ๋ง๋ฒ์ฌ ์์ด์ ํ ๋ค์ด๋
- ๋ธ๋ฃจํธํฌ์ค
- 2579 ๊ณ๋จ์ค๋ฅด๊ธฐ
- ๊ธฐ์ง๊ตญ์ค์น
- swea
- ๋ฐฑ์ค
- ์ผ์ฑ๊ธฐ์ถ
- ์๊ณ ๋ฆฌ์ฆ
- Python
- ๋ณด์์ผํ
- git ๋ฏธ๋ฌ๋ง
- ํ์ด์ฌ
- dp
- react
- 21609 ์์ด ์คํ๊ต
- BFS
- dfs
- 17406 ๋ฐฐ์ด๋๋ฆฌ๊ธฐ4
- 20056 ๋ง๋ฒ์ฌ ์์ด์ ํ์ด์ด๋ณผ
- ์์ด๋๋ง์๊ธฐ
- ์ผ์ฑ์ฝํ
์ต๊ทผ์ ์ฌ๋ผ์จ ๊ธ
- Total
- Today
- Yesterday
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ