์๋ ๋ ์ง์ง ๋์๋ฒ๋ฆฌ๊ฒ ์
์์ ๋ ๋ง๋๋ฐ ๊ณ์ ์ด๋ป๊ฒ ๊ณ ์ณ๋ ํ๋ ธ๋๊ณ ๋์์ ์ง์ง
์๋ ์ ํ๋ ์ค๋์ฟ ์ฑ ์ฐพ์์ ์ ์ผ ์ด๋ ค์ด ๋ฌธ์ ๋ค๋ก ํด๋ดค๋๋ฐ ๋ค ์ ๋ต ์ ๋์ค๋๋ฐ
๋์ฒด
๋์ฒด
๋์ฒด์ฒดใ ใ ์์ฅ
์ด๋๊ฐ ํ๋ ธ๋ค๋๊ฑฐ์ ๋์๋ฒ๋ ค ์ง์ง
๋ฐฑ์ค ์ด๋์์๋ค์ ํ ์คํธ์ผ์ด์ค๋ฅผ ์ค๋ฐฑ๊ฐ์ฉ ๋ด๋๋ผ... ์ง์ง ๋ค ๋๋ ค ๋ถ์๋ฌ ๊ฐ๊ธฐ ์ ์.....
์ ํ๋ฆฐ๊ฑด์ง๋ผ๋ ์ข ์๋ ค์ค ์ ๋ฐ๋ผ์์ใ ์๋ผ๋
์ค๋ช
์ ์๋ตํ๊ฒ ๋ค.. ํ๋ ธ๋ค์์ ์ ์ฅ ใ
# 2580.py
def check(x, y, num):
ch_row = sudoku[x]
ch_col = [sudoku[i][y] for i in range(9)]
a = (x // 3) * 3
b = (y // 3) * 3
ch_block = sudoku[a][b:b + 3] + sudoku[a + 1][b:b + 3] + sudoku[a + 2][b:b + 3]
if num in ch_row:
return False
elif num in ch_col:
return False
elif num in ch_block:
return False
else:
return True
def sdk(zeros):
if not zeros:
for i in sudoku:
print(' '.join(map(str, i)))
return
for t in range(1, 10):
i, j = zeros.pop()
if check(i, j, str(t)):
sudoku[i][j] = str(t)
sdk(zeros)
sudoku[i][j] = '0'
zeros.append([i, j])
sudoku = [[str(i) for i in input().split()] for _ in range(9)]
myzeros = [(i, j) for i in range(9) for j in range(9) if sudoku[i][j] == '0']
sdk(myzeros)
+ ๋ฐฑ์ค ์ง๋ฌธ ์ฌ๋ ธ๋๋ฐ ์ ๋ถ 0์ผ๋ก ์ฑ์์ง ๋ฌธ์ ์ ๋ ฅํ์๋ ๋ต์ด ํ๋๋ง ๋์ค๊ณ ๋ฉ์ถ๋๊ณ ๋๊ธ ๋ฌ์์ฃผ์ฌ...
๊ทธ๋์ ํด๋ดค๋๋ ๋ชจ๋ ์กฐํฉ ๋ค ์ถ๋ ฅ๋๋๋ฏ ใ ใ ํ๋ ํ๋ฆฐํธ ๋๋ฉด ๊ฐ์ข ํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ผ๋จ ํด๊ฒฐ^^..ํ์ง๋ง ์๊ฐ์ด๊ณผ..
๋์ค์ ์ธ์ ๊ฐ ํ์ด๋ณผ๊ฒ ๋ฏธ์ํ๋ค ์ค๋์ฟ ์ผ...
# 2580.py
import sys
def check(x, y, num):
ch_row = sudoku[x]
ch_col = [sudoku[i][y] for i in range(9)]
a = (x // 3) * 3
b = (y // 3) * 3
ch_block = sudoku[a][b:b + 3] + sudoku[a + 1][b:b + 3] + sudoku[a + 2][b:b + 3]
if num in ch_row:
return False
elif num in ch_col:
return False
elif num in ch_block:
return False
else:
return True
def sdk(zeros):
if not zeros:
for i in sudoku:
print(' '.join(map(str, i)))
sys.exit()
return
for t in range(1, 10):
i, j = zeros.pop()
if check(i, j, str(t)):
sudoku[i][j] = str(t)
sdk(zeros)
sudoku[i][j] = '0'
zeros.append([i, j])
sudoku = [[str(i) for i in input().split()] for _ in range(9)]
myzeros = [(i, j) for i in range(9) for j in range(9) if sudoku[i][j] == '0']
sdk(myzeros)