【题解】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;
}
相关推荐
fpcc1 小时前
ubuntu26环境下的开发环境安装处理
c++·并行编程
致Great2 小时前
科研人的 AI,不该只回答问题:我用字节TraeWork 跑了一遍真实研究任务
算法
纵有疾風起2 小时前
线性表的定义与基本操作 — 从逻辑结构到 ADT 接口
数据结构·算法·408·线性表·adt
charlie1145141913 小时前
Cinux · 第一次跳进 Ring 3:用户态与特权隔离
开发语言·c++·操作系统·开源项目
别动我齐刘海3 小时前
机器学习基础2——C++、OpenCV、点云、Open3D
c++·人工智能·opencv·机器学习·计算机视觉·机器人·ros2
测试_AI_一辰3 小时前
AI Agent 评测最隐蔽的坑-记忆
人工智能·算法·ai·自动化·ai编程
躺不平的理查德3 小时前
Windows C++ 第三方库使用流程备忘录--OpenCV
开发语言·c++
余额瞒着我当琳3 小时前
C++STL容器string--迭代器,string的接口,string的遍历,访问方式
c++
郭涤生3 小时前
rootfs 详解与裁剪优化记录
linux·c++·bsp
lucas_AI3 小时前
给YOLO检测器插 LoRA,'插对地方'比'插什么'更要命
人工智能·算法