๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
-
S2 | ๋ถํ ์ ๋ณต
์ฒซ๋ฒ์งธ์ ์๋ ์ฝ๋๊ฐ ๋ ์ ๋ต์ธ๊ฑฐ ๊ฐ๋ค( ๋๋ค ํต๊ณผํ์ง๋ง )
์ฒซ๋ฒ์งธ ์ฝ๋๋ ํญ์ 9๊ฐ์ ์กฐ๊ฐ์ผ๋ก ์๋ผ์ ์งํํ๋ค. - ์ด๊ฒ ๋ฌธ์ ๋ ๋ ๋ง๋๊ฑฐ ๊ฐ๋ค.
ํ์ง๋ง
๋๋ฒ์งธ ์ฝ๋๋ (์ฒ์ ํ์ด์ ํต๊ณผํ๊ณ ๋ค์๋ณด๋ ์ด์ํจ) 9๊ฐ์ ์กฐ๊ฐ์ด ์๋๋ค.
์ข ์ด๊ฐ ๋ค์ด์ค๋ฉด 3x3์ผ๋ก ๋ค ์๋ผ๋ฒ๋ฆฐ๋ค.
๊ทธ๋๋ ํต๊ณผํ๋ค.
์ด๊ฒ ๋๋ค??
๋ด๊ฐ ๋ฌธ์ ๋ฅผ ์ ์ดํดํ์ง ๋ชปํ๊ฑด์ง... ๋ด๊ฐ ์ง ์ฝ๋๋ฅผ ์ดํดํ์ง ๋ชปํ๊ฑด์ง ์ ๋ชจ๋ฅด๊ฒ ๋ค.
๐ป์์ค ์ฝ๋
from itertools import chain # 2์ฐจ์ ๋ฆฌ์คํธ๋ฅผ 1์ฐจ์๋ฆฌ์คํธ๋ก ๋ฐ๊ฟ์ฃผ๋ ์น๊ตฌ
def bt(paper):
global a, b, c
nn = len(paper)
if len(set(chain.from_iterable(paper))) == 1:
if paper[0][0] == -1:
a += 1
elif paper[0][0] == 0:
b += 1
else:
c += 1
else:
if nn != 3:
for i in range(0, nn, nn//3):
for j in range(0, nn, nn//3):
tmp_paper = [row[j:j + nn//3] for row in paper[i:i + nn//3]]
bt(tmp_paper)
else:
for i in range(nn):
for j in range(nn):
if paper[i][j] == -1:
a += 1
elif paper[i][j] == 0:
b += 1
else:
c += 1
n = int(input())
papers = [list(map(int, input().split())) for _ in range(n)]
a, b, c = 0, 0, 0
bt(papers)
print(f'{a}\n{b}\n{c}')
from itertools import chain
def bt(paper):
global a, b, c
nn = len(paper)
if len(set(chain.from_iterable(paper))) == 1:
if paper[0][0] == -1:
a += 1
elif paper[0][0] == 0:
b += 1
else:
c += 1
else:
if nn != 3:
for i in range(0, nn, 3):
for j in range(0, nn, 3):
tmp_paper = [row[j:j + 3] for row in paper[i:i + 3]]
bt(tmp_paper)
else:
for i in range(nn):
for j in range(nn):
if paper[i][j] == -1:
a += 1
elif paper[i][j] == 0:
b += 1
else:
c += 1
n = int(input())
papers = [list(map(int, input().split())) for _ in range(n)]
a, b, c = 0, 0, 0
bt(papers)
print(a)
print(b)
print(c)
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: BACKJOON ONLINE JUDGE
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] ๋ฐฑ์ค - 2504. ๊ดํธ์ ๊ฐ (0) | 2020.10.13 |
---|---|
[python] ๋ฐฑ์ค - 1890. ์ ํ (0) | 2020.10.12 |
[python] ๋ฐฑ์ค - 11279. ์ต๋ ํ (0) | 2020.10.10 |
[python] ๋ฐฑ์ค - 10819. ์ฐจ์ด๋ฅผ ์ต๋๋ก (0) | 2020.10.09 |
[python] ๋ฐฑ์ค - 1541. ์์ด๋ฒ๋ฆฐ ๊ดํธ (0) | 2020.10.08 |