题解:P12146 【MX-X11-T0】「蓬莱人形 Round 1」糖果曲奇巧克力
这题题最后的最小代价等于删掉糖果的最小的代价和删掉曲奇的最小代价中的较小值。
显然当操作一代价小于操作二的代价的
代码:
#include <bits/stdc++.h>
using namespace std;
long long ans1,ans2,a,b,x,y,c;
int main()
{
int t;
cin >> t;
while(t--)
{
ans1 = ans2 = 0;
cin >> a >> b >> x >> y;
if(x < 2 * y)
{
ans1 += ((a / 2) * x);
ans2 += ((b / 2) * x);
a %= 2;
b %= 2;
}
if(a > 0) ans1 += a * y;
if(b > 0) ans2 += b * y;
cout << min(ans1,ans2) << '\n';
}
return 0;
}
AC记录