nztao • 11个月前
#include <iostream>
#include <climits>
int main() {
int n;
std::cin >> n; // 需要购买的铅笔数量
int minCost = INT_MAX; // 初始化最小花费为一个较大的数
for (int i = 0; i < 3; i++) {
int count, cost;
std::cin >> count >> cost; // 读取一种包装的铅笔数量和价格
// 计算购买该种包装的铅笔所需的花费
int totalCost = (n / count) * cost; // 购买整数倍的包装
if (n % count != 0) {
totalCost += cost; // 购买剩余数量的铅笔
}
// 更新最小花费
if (totalCost < minCost) {
minCost = totalCost;
}
}
std::cout << minCost << std::endl; // 输出最小花费
return 0;
}
评论:
请先登录,才能进行评论