codeforces 1118A

本文详细解析了 CodeForces 平台上的 1118A 题目,通过比较两种购买汽油方式的成本,提供了一种高效的算法解决方案。文章包含完整的 C++ 代码实现,展示了如何根据给定条件计算最低成本。

codeforces 1118A

一升油a元2生油b元,比较2 * a与b即可

#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 2e5 + 100;
const int MAX_M  = 310;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    LL q,n,a,b;
    cin >> q;
    while (q--) {
        cin >> n >> a >> b;
        if (b >= 2 * a) {
            cout << a * n << endl;
        } else {
            cout << n / 2 * b + n % 2 * a << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值