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

@@ -6,55 +6,55 @@
#include "../utils/common.hpp"
/* コイン交換:貪欲法 */
/* 硬貨の両替:貪欲法 */
int coinChangeGreedy(vector<int> &coins, int amt) {
// coins リストはソート済みと仮定する
int i = coins.size() - 1;
int count = 0;
// 残額がなくなるまで貪欲選択を繰り返す
// 残額がなくなるまで貪欲な選択を繰り返す
while (amt > 0) {
// 残額以下で最も近い硬貨を見つける
// 残額より小さく、残額に最も近い硬貨を探す
while (i > 0 && coins[i] > amt) {
i--;
}
// coins[i] を選択する
// coins[i] を選ぶ
amt -= coins[i];
count++;
}
// 実行可能な解が見つからなければ -1 を返す
// 実行可能な方法が見つからなかった場合、-1 を返す
return amt == 0 ? count : -1;
}
/* Driver Code */
/* 実行用コード */
int main() {
// 貪欲法:大域最適解を保証できる
// 貪欲法:大域的最適解が得られることを保証できる
vector<int> coins = {1, 5, 10, 20, 50, 100};
int amt = 186;
int res = coinChangeGreedy(coins, amt);
cout << "\ncoins = ";
printVector(coins);
cout << "amt = " << amt << endl;
cout << amt << " を作るのに必要な最小硬貨枚数は " << res << endl;
cout << "目標金額 " << amt << " にするために必要な硬貨の最小枚数は " << res << endl;
// 貪欲法:大域最適解を保証できない
// 貪欲法:大域的最適解が得られることを保証できない
coins = {1, 20, 50};
amt = 60;
res = coinChangeGreedy(coins, amt);
cout << "\ncoins = ";
printVector(coins);
cout << "amt = " << amt << endl;
cout << amt << " を作るのに必要な最小硬貨枚数は " << res << endl;
cout << "実際に必要な最小枚数は 3、つまり 20 + 20 + 20" << endl;
cout << "目標金額 " << amt << " にするために必要な硬貨の最小枚数は " << res << endl;
cout << "実際に必要な最小枚数は 3 、すなわち 20 + 20 + 20" << endl;
// 貪欲法:大域最適解を保証できない
// 貪欲法:大域的最適解が得られることを保証できない
coins = {1, 49, 50};
amt = 98;
res = coinChangeGreedy(coins, amt);
cout << "\ncoins = ";
printVector(coins);
cout << "amt = " << amt << endl;
cout << amt << " を作るのに必要な最小硬貨枚数は " << res << endl;
cout << "実際に必要な最小枚数は 2、つまり 49 + 49" << endl;
cout << "目標金額 " << amt << " にするために必要な硬貨の最小枚数は " << res << endl;
cout << "実際に必要な最小枚数は 2 、すなわち 49 + 49" << endl;
return 0;
}

View File

@@ -16,16 +16,16 @@ class Item {
}
};
/* 分数ナップサック:貪欲法 */
/* 分割可能ナップサック問題:貪欲法 */
double fractionalKnapsack(vector<int> &wgt, vector<int> &val, int cap) {
// 重さと価値の 2 属性を持つ品物リストを作成
// 重さと価値の 2 つの属性を持つ品物のリストを作成する
vector<Item> items;
for (int i = 0; i < wgt.size(); i++) {
items.push_back(Item(wgt[i], val[i]));
}
// 単位価値 item.v / item.w の高い順にソートする
// 単位重さ当たりの価値 item.v / item.w の降順にソートする
sort(items.begin(), items.end(), [](Item &a, Item &b) { return (double)a.v / a.w > (double)b.v / b.w; });
// 貪欲選択を繰り返す
// 貪欲な選択を繰り返す
double res = 0;
for (auto &item : items) {
if (item.w <= cap) {
@@ -33,24 +33,24 @@ double fractionalKnapsack(vector<int> &wgt, vector<int> &val, int cap) {
res += item.v;
cap -= item.w;
} else {
// 残り容量が足りない場合は、現在の品物の一部だけをナップサックに入れる
// 残り容量が不足している場合、現在の品物の一部をナップサックに入れる
res += (double)item.v / item.w * cap;
// 残り容量がないため、ループを抜ける
// 残り容量がないため、ループを終了する
break;
}
}
return res;
}
/* Driver Code */
/* 実行用コード */
int main() {
vector<int> wgt = {10, 20, 30, 40, 50};
vector<int> val = {50, 120, 150, 210, 240};
int cap = 50;
// 貪欲法
// 貪欲アルゴリズム
double res = fractionalKnapsack(wgt, val, cap);
cout << "ナップサック容量を超えない最大価値は " << res << endl;
cout << "ナップサックの容量を超えない品物の最大価値は " << res << endl;
return 0;
}

View File

@@ -8,16 +8,16 @@
/* 最大容量:貪欲法 */
int maxCapacity(vector<int> &ht) {
// i, j を初期化し、それぞれ配列の両端に置く
// i, j を初期化し、配列の両端をそれぞれ指すようにする
int i = 0, j = ht.size() - 1;
// 初期の最大容量は 0
// 最大容量の初期値は 0
int res = 0;
// 2 枚の板が出会うまで貪欲選択を繰り返す
// 2 枚の板が出会うまで貪欲な選択を繰り返す
while (i < j) {
// 最大容量を更新する
int cap = min(ht[i], ht[j]) * (j - i);
res = max(res, cap);
// 短い方を内側へ動かす
// 低い方の仕切り板を内側に移動する
if (ht[i] < ht[j]) {
i++;
} else {
@@ -27,11 +27,11 @@ int maxCapacity(vector<int> &ht) {
return res;
}
/* Driver Code */
/* 実行用コード */
int main() {
vector<int> ht = {3, 8, 5, 2, 7, 7, 3, 4};
// 貪欲法
// 貪欲アルゴリズム
int res = maxCapacity(ht);
cout << "最大容量は " << res << endl;

View File

@@ -6,34 +6,34 @@
#include "../utils/common.hpp"
/* 最大切断積:貪欲法 */
/* 分割後の積の最大化:貪欲法 */
int maxProductCutting(int n) {
// n <= 3 のときは、必ず 1 を切り出す
// n <= 3 の場合、必ず 1 を 1 つ切り出す必要がある
if (n <= 3) {
return 1 * (n - 1);
}
// 貪欲に 3 を切り出し、a を 3 の個数、b を余りとする
// 貪欲に 3 を切り出す。a は 3 の個数、b は余り
int a = n / 3;
int b = n % 3;
if (b == 1) {
// 余りが 1 のときは、1 * 3 を 2 * 2 に変える
// 余りが 1 の場合、1 * 3 の組を 2 * 2 に変換する
return (int)pow(3, a - 1) * 2 * 2;
}
if (b == 2) {
// 余りが 2 のときは、そのままにする
// 余りが 2 の場合、何もしない
return (int)pow(3, a) * 2;
}
// 余りが 0 のときは、そのままにする
// 余りが 0 の場合、何もしない
return (int)pow(3, a);
}
/* Driver Code */
/* 実行用コード */
int main() {
int n = 58;
// 貪欲法
// 貪欲アルゴリズム
int res = maxProductCutting(n);
cout << "最大分割積は" << res << endl;
cout << "分割後の積の最大値は" << res << endl;
return 0;
}