-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[week-06-implementation] 1966, 2239 #37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from collections import deque | ||
|
||
def printer(q,index,M): | ||
cnt = 0 | ||
|
||
while q: | ||
nq = q.popleft() | ||
ni = index.popleft() | ||
if q and nq < max(q): | ||
q.append(nq) | ||
index.append(ni) | ||
continue | ||
cnt += 1 | ||
if ni == M: | ||
return cnt | ||
|
||
|
||
T = int(input()) | ||
for _ in range(T): | ||
N, M = map(int, input().split()) | ||
|
||
index = deque([i for i in range(N)]) | ||
priority = deque(list(map(int, input().split()))) | ||
|
||
print(printer(priority,index, M)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
def column_valid(row,value): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. column, row, square 별로 나누니까 더 좋은 거 같아요! |
||
|
||
for j in range(9): | ||
if sudoku[row][j] == value: | ||
return 0 | ||
|
||
return 1 | ||
|
||
|
||
|
||
def row_valid(column,value): | ||
|
||
for i in range(9): | ||
if sudoku[i][column] == value: | ||
return 0 | ||
|
||
return 1 | ||
|
||
|
||
def square_valid(i,j,value): | ||
|
||
i = i // 3 * 3 | ||
j = j // 3 * 3 | ||
|
||
for a in range(i, i + 3): | ||
for b in range(j, j + 3): | ||
if sudoku[a][b] == value: | ||
return 0 | ||
|
||
return 1 | ||
|
||
def dfs(cnt): | ||
if cnt == len(zero): | ||
return True | ||
|
||
r, c = zero[cnt] | ||
for i in range(1,10): | ||
if column_valid(r,i) and row_valid(c,i) and square_valid(r,c,i): | ||
sudoku[r][c] = i | ||
check = dfs(cnt + 1) | ||
if check: | ||
return True | ||
sudoku[r][c] = 0 | ||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. column, row, square 함수로 나누니 이 부분이 확실히 깔끔한 것 같아요! |
||
|
||
|
||
|
||
sudoku = [list(map(int, input())) for _ in range(9)] | ||
zero = [] | ||
for i in range(9): | ||
for j in range(9): | ||
if sudoku[i][j] == 0: | ||
zero.append((i,j)) | ||
|
||
dfs(0) | ||
for i in range(9): | ||
for j in range(9): | ||
print(sudoku[i][j], end='') | ||
print() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM😀👍🏻 |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python에서 큐에 대해 max가 되는군요 ..! 😲