1 条题解

  • 0
    @ 2024-8-2 16:19:44

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        int n, m; // n个硬币,凑m分
        int x, y;
        int ans = 0;
        cin >> n >> m;
        
        // 枚举5分能凑出的数量
        for (int i = 0; i <= m / 5; i++) {
            x = m - i * 5; // 凑完5分剩余的金额
            
            // 枚举2分能凑出的数量
            for (int j = 0; j <= x / 2; j++) {
                y = x - j * 2; // 凑完5分和2分剩余的金额
                
                // 剩余金额只能凑1分,总数量需要n个
                if (i + j + y == n) {
                    ans++;
                }
            }
        }
        cout << ans;
                    return 0;
    }
    
    
    • 1

    信息

    ID
    1006
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    2
    已通过
    2
    上传者