某公司使用某种原材料加工两种规格的产品,其中生产每件A产品消耗原材料56kg,生产每件B产品消耗原材料64kg。假设该公司现有800kg的原材料,编写程序计算A、B各生产多少件的剩余的原材料最少?
void main()
{
//min 代表剩余最少的原料
//flag代表是否继续程序,当找到与min相等的等式,则退出
int min = 0, flag = 1;
//weightSum=总重量
int weightSum = 800, weightA = 56, weightB = 64;
while (flag) {
for (int a = 0; weightA * a <= weightSum; a++) { for (int b = 0; weightB * b + weightA * a <= weightSum; b++) { if (min == (weightSum - (weightB * b + weightA * a))) { printf("A=%d,B=%d /n", a, b); flag = 0; } } } //最低剩余重量不能超过总重量 if (flag && min != weightSum) { min++;
某公司使用某种原材料加工两种规格的产品,其中生产每件A产品消耗原材料56kg,生产每件B产品消耗原材料64kg。假设该公司现有800kg的原材料,编写程序计算A、B各生产多少件的剩余的原材料最少?最先出现在Python成神之路。
共有 0 条评论