Skip to content

Comments

queens#2

Open
shannami wants to merge 1 commit intomainfrom
homework1
Open

queens#2
shannami wants to merge 1 commit intomainfrom
homework1

Conversation

@shannami
Copy link
Owner

@shannami shannami commented Oct 9, 2025

add a task about queens

@shannami shannami requested a review from KubEF October 9, 2025 18:17
1) queen1(перебор)
- Изначально поставить ферзя n вариантов, далее (n-1) вариантов и т.д. O(n!)
- Для всех перестановок проверяется диагональ: два вложенных цикла это примерно O(n**2)
- Общая сложность O(n!*n**2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Обычно в markdown для формул используют latex: $O(n! \cdot n^2)$ $\to$ $O(n!\cdot n^2)$

Comment on lines +9 to +10
return 0
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Почему не True и False?

Comment on lines +1 to +25
"""
def queen(n):
cols = [None]*n
k = 0

def diagonal(row, col):
for r in range(row):
if cols[r] == col or abs(cols[r] - col) == abs(
r - row
): # вертикаль или диагональ совпадают
return 0
return 1

def solve(row=0):
nonlocal k
if row == n:
k += 1
return
for col in range(n):
if diagonal(row, col):
cols[row] = col # ставим ферзя
solve(row + 1) # идём в следующую строку

solve()
return k
Copy link
Collaborator

Choose a reason for hiding this comment

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

Что это?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Предполагается, что вы придумаете сильно более быстрый алгоритм. Я дал подсказки некоторым из ваших одногруппников, проявите софт скиллы)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants