【题解】NC219035 春游(模拟 - 分情况讨论)

https://ac.nowcoder.com/acm/problem/219035

cpp 复制代码
#include <iostream>

using namespace std;
long long typedef LL;

LL fun(LL n, LL a, LL b) {
    if (n <= 2) return min(a, b);
    
    LL ret = 0;
    
    if (a * 3 < b * 2) // 尽可能选择双人船 
    {
        ret += n / 2 * a;
        n %= 2;
        if(n) ret += min(min(a, b), b - a);
    }
    else // 尽可能选择三人船
    {
        ret += n / 3 * b;
        n %= 3;
        if (n == 1) ret += min(min(a, b), 2*a - b);
        else if (n == 2) ret += min(min(a, b), 3*a - b);
    }
    return ret;
}

int main()
{
    int t;
    cin >> t;
    while (t--) {
        LL n, a, b;
        cin >> n >> a >> b;
        cout << fun(n, a, b) << endl;
    }
    
    return 0;
}
相关推荐
To_OC4 小时前
LC 51 N 皇后:我以为难的是回溯,结果栽在了对角线下标
javascript·算法·leetcode
2401_841495645 小时前
【操作系统】进程同步与互斥实验报告
c++·算法·操作系统·进程·并发·同步·互斥
fqbqrr5 小时前
2607C++,soui与安卓
c++·soui
fqbqrr8 小时前
2607C++,使用微软detours勾挂工具
c++
爱刷碗的苏泓舒9 小时前
PPP-AR 中的参考星选取:数学原理、评价指标与切换处理
算法·gnss·模糊度固定·ppp-ar·星间单差·参考星·卫星端偏差
蓝悦无人机11 小时前
C++基础 — 函数总结
开发语言·c++
烬羽11 小时前
递归老写崩?一个"退回"公式,把回溯题变成填空题
javascript·深度学习·算法
闪电悠米12 小时前
力扣hot100-41.缺失的第一个正数-原地哈希详解
数据结构·算法·哈希算法
星空露珠12 小时前
28种颜色对应名称,
开发语言·数据库·算法·游戏·lua