Skip to content

Commit 0e73631

Browse files
authored
Merge pull request #50 from 24-Algorithm/minjeong
Minjeong / 7์›” 5์ฃผ์ฐจ / 4๋ฌธ์ œ
2 parents 4910c87 + 9fe01ef commit 0e73631

4 files changed

+101
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
def find_number_of_paper(x_start, y_start, n):
5+
global white_cnt, blue_cnt
6+
check_sum = 0 # ์ƒ‰์ข…์ด๊ฐ€ ๋งŒ๋“ค์–ด์ง€๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
7+
for i in range(x_start, x_start + n):
8+
for j in range(y_start, y_start + n):
9+
check_sum += colored_paper[i][j]
10+
if check_sum == 0: # ํ•˜์–€ ์ƒ‰์ข…์ด๋ผ๋ฉด
11+
white_cnt += 1
12+
elif check_sum == n * n: # ํŒŒ๋ž€ ์ƒ‰์ข…์ด๋ผ๋ฉด
13+
blue_cnt += 1
14+
else: # ํ•ด๋‹น ์‚ฌํ•ญ ์—†์œผ๋ฉด ๋‹ค์‹œ ๋ถ„ํ• 
15+
find_number_of_paper(x_start, y_start, n // 2)
16+
find_number_of_paper(x_start + n // 2, y_start, n // 2)
17+
find_number_of_paper(x_start, y_start + n // 2, n // 2)
18+
find_number_of_paper(x_start + n // 2, y_start + n // 2, n // 2)
19+
20+
n = int(input()) # ํ•œ ๋ณ€์˜ ๊ธธ์ด
21+
colored_paper = [] # ์ •์‚ฌ๊ฐํ˜•์นธ์˜ ์ƒ‰
22+
for _ in range(n):
23+
li = list(map(int, input().split()))
24+
colored_paper.append(li)
25+
26+
white_cnt = 0 # ํ–์–€์ƒ‰ ์ƒ‰์ข…์ด์˜ ๊ฐœ์ˆ˜
27+
blue_cnt = 0 # ํŒŒ๋ž€์ƒ‰ ์ƒ‰์ข…์ด์˜ ๊ฐœ์ˆ˜
28+
29+
find_number_of_paper(0, 0, n)
30+
31+
print(white_cnt)
32+
print(blue_cnt)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
def z_order(N, r, c):
5+
if N == 0: # Base case: ํฌ๊ธฐ๊ฐ€ 1x1์ธ ๊ฒฝ์šฐ
6+
return 0
7+
half = 2 ** (N - 1)
8+
if r < half and c < half: # 1์‚ฌ๋ถ„๋ฉด
9+
return z_order(N - 1, r, c)
10+
elif r < half and c >= half: # 2์‚ฌ๋ถ„๋ฉด
11+
return half * half + z_order(N - 1, r, c - half)
12+
elif r >= half and c < half: # 3์‚ฌ๋ถ„๋ฉด
13+
return 2 * half * half + z_order(N - 1, r - half, c)
14+
else: # 4์‚ฌ๋ถ„๋ฉด
15+
return 3 * half * half + z_order(N - 1, r - half, c - half)
16+
17+
N, r, c = map(int, input().split())
18+
print(z_order(N, r, c))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
def quad_tree(x_start, y_start, n):
5+
global answer
6+
cnt = 0 # ์••์ถ•์ด ๊ฐ€๋Šฅํ•œ ์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜
7+
for i in range(x_start, x_start + n):
8+
for j in range(y_start, y_start + n):
9+
cnt += grid[i][j]
10+
11+
if cnt == 0: # ๋‹ค ๋”ํ•œ ๊ฐ’์ด 0์ด๋ผ๋ฉด 0์œผ๋กœ ์••์ถ• ๊ฐ€๋Šฅ
12+
answer += "0"
13+
elif cnt == n * n: # ๋‹ค ๋”ํ•œ ๊ฐ’์ด 1*n*n์ด๋ผ๋ฉด 1๋กœ ์••์ถ• ๊ฐ€๋Šฅ
14+
answer += "1"
15+
else: # ํ•ด๋‹น ์‚ฌํ•ญ ์—†์œผ๋ฉด ๋ถ„ํ• 
16+
answer += "(" # ๊ฐ€์žฅ ๋จผ์ € ๊ด„ํ˜ธ ์—ด๊ณ 
17+
quad_tree(x_start, y_start, n // 2) # ์™ผ์ชฝ ์œ„
18+
quad_tree(x_start, y_start + n // 2, n // 2) # ์˜ค๋ฅธ์ชฝ ์œ„
19+
quad_tree(x_start + n // 2, y_start, n // 2) # ์™ผ์ชฝ ์•„๋ž˜
20+
quad_tree(x_start + n // 2, y_start + n // 2, n // 2) # ์˜ค๋ฅธ์ชฝ ์•„๋ž˜
21+
answer += ")" # ํ˜ธ์ถœ์ด ๋ชจ๋‘ ๋๋‚  ๊ฒฝ์šฐ ๊ด„ํ˜ธ ๋‹ซ์Œ
22+
23+
n = int(input()) # ์˜์ƒ์˜ ํฌ๊ธฐ
24+
grid = [] # ์˜์ƒ ๋ฐฐ์—ด
25+
for _ in range(n):
26+
li = input().strip()
27+
li = list(map(int, li)) # ๋ฌธ์ž์—ด์„ intํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ๋กœ ์ €์žฅ
28+
grid.append(li)
29+
30+
answer = ""
31+
quad_tree(0, 0, n)
32+
33+
# ์ •๋‹ต ์ถœ๋ ฅ
34+
print(answer)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(n):
2+
ans = 0
3+
4+
while n > 0:
5+
if n % 2 == 0:
6+
n //= 2
7+
else:
8+
n -= 1
9+
ans += 1
10+
11+
return ans
12+
13+
'''
14+
# ๋‹ค๋ฅธ ํ’€์ด:
15+
def solution(n):
16+
return bin(n).count('1')
17+
'''

0 commit comments

Comments
ย (0)