1 条题解
-
0
解题思路
在这个问题中,你可以直接枚举你想要制作的牛肉汉堡和鸡肉汉堡的数量,检查是否有足够的原料,然后更新答案。
如果你想卖出 个牛肉汉堡和 个鸡肉汉堡,那么你需要:
- 个牛肉饼,
- 个鸡肉排,
- 个面包。
因此,只需枚举所有可能的 和 组合,检查是否满足:
- ,
- ,
- ,
然后计算利润 ,取最大值即可。
由于 ,枚举 和 的复杂度为 ,在 的情况下完全可行。
#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
- 上传者