【题解】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;
}
相关推荐
午彦琳12 分钟前
2026.9.17
数据结构·算法·leetcode
shada29 分钟前
Boost.Process v2 在旧内核上报 `assign: Bad file descriptor`
c++
木井巳35 分钟前
【记忆化搜索】不同路径
java·算法·leetcode·深度优先·剪枝·推荐算法
别动我齐刘海1 小时前
ROS2 Jazzy + C++ 实战路线——基础学习2
c++·人工智能·vscode·python·学习·机器学习·机器人
怕浪猫2 小时前
从 Windows 换到 Mac 三个月,我真香了
算法·面试·架构
朝朝辞暮i2 小时前
C++第 2 课
c++
代码中介商2 小时前
C++ 预约系统实战(三):服务端实现——libevent 事件驱动与业务路由
c++·json·c/s
aichitang20242 小时前
前端小skill
前端·人工智能·算法·ai·前端框架
布莱克6053 小时前
C++中的内存分区详解
c++
All for pursuit.3 小时前
【链表-9】146.LRU缓存
数据结构·c++·算法·leetcode