题解:SP7185 BYECAKES - Bye Bye Cakes
题目要求不浪费且最少,那么能做的蛋糕的数量就是每种食材能做出的蛋糕的数量的最大值。
蛋糕数量为:\(\max\{\lceil \frac{E}{E'} \rceil,\lceil \frac{F}{F'} \rceil,\lceil \frac{S}{S'} \rceil,\lceil \frac{M}{M'} \rceil\}\)。
然后计算出还需要买的数量即可。
代码:
#include<iostream>
using namespace std;
int main(){
for(;;){
int E,F,S,M,Ep,Fp,Sp,Mp;
cin>>E>>F>>S>>M>>Ep>>Fp>>Sp>>Mp;
if(E==-1)return 0;
int n=0;
n=max(n,(E+Ep-1)/Ep);
n=max(n,(F+Fp-1)/Fp);
n=max(n,(S+Sp-1)/Sp);
n=max(n,(M+Mp-1)/Mp);
cout<<Ep*n-E<<" ";
cout<<Fp*n-F<<" ";
cout<<Sp*n-S<<" ";
cout<<Mp*n-M<<endl;
}
}

浙公网安备 33010602011771号