M. [GESP]L5-202506-Q3247-S

    客观题

[GESP]L5-202506-Q3247-S

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

硬币找零问题中要求找给客户最少的硬币。coins 存储可用硬币规格,单位为角,假设规格都小于 10 角,且一定有 1 角规格。amount 为要找零的金额,约定必须为 1 角的整数倍。输出为每种规格及其数量,按规格从大到小输出,如果某种规格不必要,则输出为 0。下面是其实现代码,相关说法正确的是( )。

const int MAX_COINS = 10;
int result[MAX_COINS] = {0};  // 假设最多10种面额

int find_coins(const vector<int>& coins, int amount) {
    sort(coins.begin(), coins.end(), greater<int>());

    int n = coins.size();

    for (int i = 0; i < n; ++i) {
        int coin = coins[i];
        int num = amount / coin;
        result[i] = num;
        amount -= num * coin;
        if (amount == 0) break;
    }

    cout << "找零方案如下:" << endl;
    for (int i = 0; i < n; ++i) {
        cout << sorted_coins[i] << "角需要" << result[i] << "枚" << endl;
    }

    return 0;
}

{{ select(1) }}

  • 上述代码采用贪心算法实现
  • 针对本题具体要求,上述代码总能找到最优解
  • 上述代码采用枚举算法
  • 上述代码采用分治算法

GESP 2025.06 C++ 五级 全真模拟赛

未参加
状态
已结束
规则
OI
题目
27
开始于
2026-11-20 13:32
结束于
2026-11-25 13:32
持续时间
2 小时
主持人
参赛人数
0