Skip to content
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

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
25 changes: 25 additions & 0 deletions week06-implementation/leGit-y/1966.py
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python에서 큐에 대해 max가 되는군요 ..! 😲

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))
60 changes: 60 additions & 0 deletions week06-implementation/leGit-y/2239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
def column_valid(row,value):
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM😀👍🏻