Bug fixes and improvements (#1472)

* preorder, inorder, postorder -> pre-order, in-order, post-order

* Bug fixes

* Bug fixes

* Update what_is_dsa.md

* Sync zh and zh-hant versions

* Sync zh and zh-hant versions.

* Update performance_evaluation.md and time_complexity.md

* Add @khoaxuantu to the landing page.

* Sync zh and zh-hant versions

* Add @ khoaxuantu to the landing page of zh-hant and en versions.

* Sync zh and zh-hant versions.

* Small improvements

* @issue :  #1450 (#1453)

Fix writing "obsecure" to "obscure"

Co-authored-by: Gaya <kheliligaya@gmail.com>

* Update the definition of "adaptive sorting".

* Update n_queens_problem.md

* Sync zh, zh-hant, and en versions.

---------

Co-authored-by: Gaya-Khelili <50716339+Gaya-Khelili@users.noreply.github.com>
Co-authored-by: Gaya <kheliligaya@gmail.com>
This commit is contained in:
Yudong Jin
2024-07-30 16:56:59 +08:00
committed by GitHub
parent 89a911583d
commit c9041c5c5e
34 changed files with 79 additions and 55 deletions

View File

@ -28,7 +28,11 @@
為了滿足列約束,我們可以利用一個長度為 $n$ 的布林型陣列 `cols` 記錄每一列是否有皇后。在每次決定放置前,我們透過 `cols` 將已有皇后的列進行剪枝,並在回溯中動態更新 `cols` 的狀態。
那麼,如何處理對角線約束呢?設棋盤中某個格子的行列索引為 $(row, col)$ ,選定矩陣中的某條主對角線,我們發現該對角線上所有格子的行索引減列索引都相等,**即對角線上所有格子的 $row - col$ 為恆定值**。
!!! tip
請注意,矩陣的起點位於左上角,其中行索引從上到下增加,列索引從左到右增加。
那麼,如何處理對角線約束呢?設棋盤中某個格子的行列索引為 $(row, col)$ ,選定矩陣中的某條主對角線,我們發現該對角線上所有格子的行索引減列索引都相等,**即主對角線上所有格子的 $row - col$ 為恆定值**。
也就是說,如果兩個格子滿足 $row_1 - col_1 = row_2 - col_2$ ,則它們一定處在同一條主對角線上。利用該規律,我們可以藉助下圖所示的陣列 `diags1` 記錄每條主對角線上是否有皇后。