mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-04 04:02:48 +08:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user