Re-translate the Japanese version (#1871)

* Retranslate Japanese docs with GPT-5.4

* Retranslate Japanese code with GPT-5.4
This commit is contained in:
Yudong Jin
2026-03-30 07:30:15 +08:00
committed by GitHub
parent fe6443235b
commit d7b2277d2b
1444 changed files with 83312 additions and 8363 deletions

View File

@@ -6,40 +6,40 @@
#include "../utils/common.hpp"
/* バックトラッキングアルゴリズムn クイーン */
/* バックトラッキングN クイーン */
void backtrack(int row, int n, vector<vector<string>> &state, vector<vector<vector<string>>> &res, vector<bool> &cols,
vector<bool> &diags1, vector<bool> &diags2) {
// すべての行が配置されたら、解を記録
// すべての行への配置が完了したら、解を記録する
if (row == n) {
res.push_back(state);
return;
}
// すべての列を走査
for (int col = 0; col < n; col++) {
// セルに対応する主対角線と副対角線を計算
// このマスに対応する主対角線と副対角線を計算
int diag1 = row - col + n - 1;
int diag2 = row + col;
// 剪定:セルの列、主対角線、副対角線にクイーンを配置することを許可しない
// 枝刈り:そのマスの列、主対角線、副対角線にクイーンがあってはならない
if (!cols[col] && !diags1[diag1] && !diags2[diag2]) {
// 試行:セルにクイーンを
// 試行:そのマスにクイーンを置
state[row][col] = "Q";
cols[col] = diags1[diag1] = diags2[diag2] = true;
// 次の行配置
// 次の行配置する
backtrack(row + 1, n, state, res, cols, diags1, diags2);
// 回退:セルを空のスポットに復元
// 戻す:そのマスを空きマスに戻す
state[row][col] = "#";
cols[col] = diags1[diag1] = diags2[diag2] = false;
}
}
}
/* n クイーンを解く */
/* N クイーンを解く */
vector<vector<vector<string>>> nQueens(int n) {
// n*n サイズのチェスボードを初期化'Q' はクイーンを表し、'#' は空のスポットを表す
// n*n の盤面を初期化する。'Q' はクイーン、'#' は空きマスを表す
vector<vector<string>> state(n, vector<string>(n, "#"));
vector<bool> cols(n, false); // クイーンある列を記録
vector<bool> diags1(2 * n - 1, false); // クイーンある主対角線を記録
vector<bool> diags2(2 * n - 1, false); // クイーンある副対角線を記録
vector<bool> cols(n, false); // 列にクイーンある記録
vector<bool> diags1(2 * n - 1, false); // 主対角線にクイーンあるを記録
vector<bool> diags2(2 * n - 1, false); // 副対角線にクイーンあるを記録
vector<vector<vector<string>>> res;
backtrack(0, n, state, res, cols, diags1, diags2);
@@ -47,13 +47,13 @@ vector<vector<vector<string>>> nQueens(int n) {
return res;
}
/* ドライバーコード */
/* Driver Code */
int main() {
int n = 4;
vector<vector<vector<string>>> res = nQueens(n);
cout << "チェスボードの次元を " << n << " として入力" << endl;
cout << "クイーン配置解の総数 = " << res.size() << endl;
cout << "入力した盤面の縦横は " << n << endl;
cout << "クイーン配置方法は全部で " << res.size() << " 通り" << endl;
for (const vector<vector<string>> &state : res) {
cout << "--------------------" << endl;
for (const vector<string> &row : state) {
@@ -62,4 +62,4 @@ int main() {
}
return 0;
}
}