1 条题解

  • 0
    @ 2026-5-5 8:09:47

    解题思路

    在这个问题中,你可以直接枚举你想要制作的牛肉汉堡和鸡肉汉堡的数量,检查是否有足够的原料,然后更新答案。

    如果你想卖出 xx 个牛肉汉堡和 yy 个鸡肉汉堡,那么你需要:

    • xx 个牛肉饼,
    • yy 个鸡肉排,
    • 2(x+y)2(x + y) 个面包。

    因此,只需枚举所有可能的 xxyy 组合,检查是否满足:

    • xpx \le p
    • yfy \le f
    • 2(x+y)b2(x + y) \le b

    然后计算利润 xh+ycx \cdot h + y \cdot c,取最大值即可。

    由于 b,p,f100b, p, f \le 100,枚举 xxyy 的复杂度为 O(100×100)=O(104)O(100 \times 100) = O(10^4),在 t100t \le 100 的情况下完全可行。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int t;
    int b, p, f;
    int h, c;
    
    int main() {
        cin >> t;
        for(int tc = 0; tc < t; ++tc){
            cin >> b >> p >> f;
            cin >> h >> c;
    
            b /= 2;
            if(h < c){
                swap(h, c);
                swap(p, f);
            }
    
            int res = 0;
    
            int cnt = min(b, p);
            b -= cnt, p -= cnt;
            res += h * cnt; 
            
            cnt = min(b, f);
            b -= cnt, f -= cnt;
            res += c * cnt; 
                
            cout << res << endl;
        }
        return 0;
    }
    
    • 1

    信息

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