Description
n n n个人住宿,有双人间和三人间,价格分别为 p 2 , p 3 p_2,p_3 p2,p3,问最小花费
Input
三个整数 n , p 2 , p 3 ( 1 ≤ n , p 2 , p 3 ≤ 1 0 9 ) n,p_2,p_3(1\le n,p_2,p_3\le 10^9) n,p2,p3(1≤n,p2,p3≤109)
Output
输出最小花费
Sample Input
4 2 3
Sample Output
4
Solution
绝大部分人会选择性价比高的房间住,最后由于人数原因可能会选择一个性价比低的房间,但是此时所选房间数量不会超过 3 3 3,小范围枚举,剩下放假全部选择性价比高的房间,更新最优解即可
Code
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
int n,p2,p3;
while(~scanf("%d%d%d",&n,&p2,&p3))
{
ll ans=2e18;
for(int i=0;i<=3;i++)
for(int j=0;j<=2;j++)
{
ll temp=(ll)i*p2+(ll)j*p3;
int num=0;
if(n-2*i-3*j>0)num=(n-2*i-3*j+5)/6;
temp+=min(3ll*p2,2ll*p3)*num;
ans=min(ans,temp);
}
printf("%lld\n",ans);
}
return 0;
}