第23653题 单选题
判断过河问题的C++实现代码所采用的算法思想

现在有 n 个人要过河,每只船最多载2人,船的承重为100kg。数组 weight 中保存有 n 个人的体重(单位为kg),已经按从小到大排好序,如下代码输出过河所需要的船的数目,该代码采用的思想为( )。

int i, j;
int count = 0;
for (i = 0, j = n - 1; i < j; j--) {
    if (weight[i] + weight[j] <= 100) {
        i++;
    }
    count++;
}
printf("过河的船数:%d\n", count);
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析