Retranslate the complete Japanese online edition from Chinese (#2008)

* Retranslate the complete Japanese online edition from Chinese

* Fit Japanese homepage labels and localize heading permalinks

* Point Japanese contribution instructions to the Japanese preview

* Replace locale conditionals with multilingual UI tables
This commit is contained in:
Yudong Jin
2026-10-30 02:12:26 +08:00
committed by GitHub
parent 455e8c1281
commit 7257641e0e
1987 changed files with 23531 additions and 23261 deletions

View File

@@ -4,51 +4,51 @@
* Author: Justin (xiefahit@gmail.com)
*/
/* バックトラッキング:N クイーン */
/* バックトラッキング:n クイーン */
function backtrack(row, n, state, res, cols, diags1, diags2) {
// すべての行への配置が完了したら、解を記録する
// すべての行への配置が終わったら、解を記録する
if (row === n) {
res.push(state.map((row) => row.slice()));
return;
}
// すべての列を走査
// すべての列を走査する
for (let col = 0; col < n; col++) {
// このマスに対応する主対角線と副対角線を計算
// このマスに対応する主対角線と副対角線を求める
const diag1 = row - col + n - 1;
const 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 クイーン問題を解く */
function nQueens(n) {
// n*n の盤面を初期化する。'Q' はクイーン、'#' は空きマスを表す
const state = Array.from({ length: n }, () => Array(n).fill('#'));
const cols = Array(n).fill(false); // 列にクイーンがあるか記録
const diags1 = Array(2 * n - 1).fill(false); // 主対角線にクイーンがあるかを記録
const diags2 = Array(2 * n - 1).fill(false); // 副対角線にクイーンがあるかを記録
const cols = Array(n).fill(false); // 列にクイーンがあるかどうかを記録する
const diags1 = Array(2 * n - 1).fill(false); // 主対角線にクイーンがあるかどうかを記録する
const diags2 = Array(2 * n - 1).fill(false); // 副対角線にクイーンがあるかどうかを記録する
const res = [];
backtrack(0, n, state, res, cols, diags1, diags2);
return res;
}
// Driver Code
// 実行用コード
const n = 4;
const res = nQueens(n);
console.log(`入力する盤面の縦横は ${n}`);
console.log(`クイーン配置の解法は全部で ${res.length} 通り`);
console.log(`入力した盤面の縦横の長さは ${n}`);
console.log(`クイーンの配置方法は全部で ${res.length} 通り`);
res.forEach((state) => {
console.log('--------------------');
state.forEach((row) => console.log(row));