From 3f3c6d03ceff01d862621f4b3e90bb9bf843e48e Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 11 Aug 2020 06:12:03 +0900 Subject: [PATCH] =?UTF-8?q?(N-Queen,=20=EC=8A=A4=EB=8F=84=EC=BF=A0)=20=3D>?= =?UTF-8?q?=20{=EC=93=B0=EB=A0=88=EA=B8=B0}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zeta_python/2580.py | 52 +++++++++++++++++++++++++++++++++ zeta_python/completed/2239.py | 55 +++++++++++++++++++++++++++++++++++ zeta_python/completed/9663.py | 2 ++ 3 files changed, 109 insertions(+) create mode 100644 zeta_python/2580.py create mode 100644 zeta_python/completed/2239.py create mode 100644 zeta_python/completed/9663.py diff --git a/zeta_python/2580.py b/zeta_python/2580.py new file mode 100644 index 0000000..34a8582 --- /dev/null +++ b/zeta_python/2580.py @@ -0,0 +1,52 @@ +from collections import deque +import sys + +Map = list() +K = [] # pos list + +for i in range(9): + t = list(map(int, sys.stdin.readline().split())) + for j in range(9): + if t[j] == 0: + K.append((i, j)) # pos + Map.append(t) + +kl = len(K) + + +def check_possibility(l): + wbr = [] + for num in range(1, 10): + if num in Map[K[l][0]]: + continue + elif num in (Map[i][K[l][1]] for i in range(9)): + continue + tx = K[l][0] // 3 * 3 + ty = K[l][1] // 3 * 3 + if any(num in s[ty:ty + 3] for s in Map[tx:tx + 3]): + continue + wbr.append(num) + return wbr + + +T = deque() +for i in check_possibility(0): + T.append((i, 0)) + +beforeDepth = 0 + +while T: + now, d = T.pop() + if d >= beforeDepth: + Map[K[d][0]][K[d][1]] = now + else: + for i in range(d + 1, beforeDepth + 1): + Map[K[i][0]][K[i][1]] = 0 + Map[K[d][0]][K[d][1]] = now + if d == kl - 1: + break + for i in check_possibility(d + 1): + T.append((i, d + 1)) + beforeDepth = d +for row in Map: + print(" ".join(map(str, row))) diff --git a/zeta_python/completed/2239.py b/zeta_python/completed/2239.py new file mode 100644 index 0000000..e87d915 --- /dev/null +++ b/zeta_python/completed/2239.py @@ -0,0 +1,55 @@ +import sys + +Map = list() +K = [] # pos list + +for i in range(9): + t = list(map(int, input())) + for j in range(9): + if t[j] == 0: + K.append((i, j)) # pos + Map.append(t) + +kl = len(K) + + +def check_possibility(l): + wbr = [] + for num in range(1, 10): + if num in Map[K[l][0]]: + continue + elif num in [Map[i][K[l][1]] for i in range(9)]: + continue + tx = K[l][0] // 3 * 3 + ty = K[l][1] // 3 * 3 + if any(num in s[ty:ty + 3] for s in Map[tx:tx + 3]): + continue + wbr.append(num) + return wbr + + +T = [] +for i in check_possibility(0)[::-1]: + T.append((i, 0)) + +beforeDepth = 0 + +while T: + now, d = T.pop() + if d >= beforeDepth: + Map[K[d][0]][K[d][1]] = now + else: + for i in range(d + 1, beforeDepth + 1): + Map[K[i][0]][K[i][1]] = 0 + Map[K[d][0]][K[d][1]] = now + if d == kl - 1: + break + for i in check_possibility(d + 1)[::-1]: + T.append((i, d + 1)) + beforeDepth = d +for row in Map: + for col in row: + print(col, end='') + print() + +# ㄹㅇ 재귀를 써야 하는거신가? 일단 함수를 적합도 함수를 손봐주볼까? diff --git a/zeta_python/completed/9663.py b/zeta_python/completed/9663.py new file mode 100644 index 0000000..8400872 --- /dev/null +++ b/zeta_python/completed/9663.py @@ -0,0 +1,2 @@ +print([0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596][int(input())]) +# 파이썬 노답;