AT_abc331_b 题解

· · 个人记录

题目链接:

[ABC331B] Buy One Carton of Milk

题意简述:

现在 6 个鸡蛋卖 a 元,8 个鸡蛋卖 b 元,12 个鸡蛋卖 c 元,求你至少买 n 个鸡蛋时至少要花多少钱。

解题思路:

由于 n \le 100,因此我们直接暴力枚举 a,b,c 的值即可,时间复杂度 O(n^3),可以通过此题。

参考代码:

#include<bits/stdc++.h>
using namespace std;
long long n,a,b,c,ans=1e18;
#define lowbit(x) x&-x
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
int main()
{
    IOS;
    cin>>n>>a>>b>>c;
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
            for(int k=0;k<=100;k++)
                if(i*6+j*8+k*12>=n)
                    ans=min(ans,i*a+j*b+k*c);
    cout<<ans;
    QwQ;
}