题目:
阿潘水果店以出售水果拼盘盈利。 该店铺共提供两种拼盘:
拼盘 1:包含 1 个苹果,1 个香蕉。
拼盘 2:包含 1 个梨,1 个橙子,1 个香蕉。
已知阿潘店共有 a 个苹果,b 个梨,c 个橙子,d 个香蕉。 拼盘 1 的利润为 e 元,拼盘 2 的利润为 f 元。 水果店的生意很好,所有拼好的拼盘都会销售一空。
请问,利用现有水果拼装水果拼盘,能够获得的最大利润是多少?
注意,也许会有一些水果用不完,但这并不重要。
Input
每组数据包含 6 个整数,依次为 a,b,c,d,e,f。
1≤a,b,c,d≤100000, 1≤e,f≤1000。
Output
每组数据输出一行结果,表示最大利润。
Sample 1
Inputcopy | Outputcopy |
---|---|
4 5 6 3 1 2 | 6 |
Sample 2
Inputcopy | Outputcopy |
---|---|
12 11 13 20 4 6 | 102 |
Sample 3
Inputcopy | Outputcopy |
---|---|
17 14 5 21 15 17 | 325 |
Note
It is possible to compose three suits of the second type in the first example, and their total cost will be 66. Since all jackets will be used, it's impossible to add anything to this set.
The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is 9 \cdot 4 + 11 \cdot 6 = 1029⋅4+11⋅6=102.
思路:
由于两种拼盘都需要香蕉而且除了香蕉以外没有其他共用的水果,所以我们可以根据两个拼盘的利润来考虑优先使用哪个拼盘。
当拼盘1的利润高于2,那么就先使用1拼盘,如果苹果的个数多于香蕉,那么用香蕉数乘以拼盘1的利润,即可;如果苹果个数小于香蕉,那么总利润就等于苹果数乘以拼盘1的利润+香蕉数减去苹果数与梨和橙子之间的最小数乘以拼盘2的利润;
当拼盘2的利润高于1时,那么就优先使用2拼盘,选出梨,橙子和香蕉个数的最小值,如果香蕉数大于最小值则总利润等于最小值乘以拼盘2的利润+香蕉数减去最小值与苹果数比较的较小值乘以拼盘1的利润;如果最小值等于香蕉数,那么用香蕉数乘以拼盘2的利润,即可。
代码:
#include<stdio.h>
int main()
{
int a,b,c,d,e,f,sum=0,min1,min2,m;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
if(e>=f)
{
if(a>=d)
sum=d*e;
else
{
min1=b;
if(min1>c)
min1=c;
if(min1>d-a)
min1=d-a;
printf("%d\n",min1);
sum=a*e+min1*f;
}
}
else
{
min2=b;
if(min2>c)
min2=c;
if(min2>d)
min2=d;
m=d-min2;
if(m>a)
m=a;
printf("%d\n",min2);
sum=min2*f+m*e;
}
printf("%d\n",sum);
return 0;
}