【题解】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;
}
相关推荐
米粒123 分钟前
力扣算法刷题 Day 31 (贪心总结)
算法·leetcode·职场和发展
少许极端26 分钟前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法
AlenTech1 小时前
647. 回文子串 - 力扣(LeetCode)
算法·leetcode·职场和发展
py有趣1 小时前
力扣热门100题之合并两个有序链表
算法·leetcode·链表
8Qi81 小时前
LeetCode热题100--45.跳跃游戏 II
java·算法·leetcode·贪心算法·编程
foundbug9992 小时前
基于STM32的步进电机加减速程序设计(梯形加减速算法)
stm32·单片机·算法
CheerWWW2 小时前
C++学习笔记——this关键字、对象生命周期(栈作用域)、智能指针、复制与拷贝构造函数
c++·笔记·学习
lucky九年2 小时前
GO语言模拟C++封装,继承,多态
开发语言·c++·golang
北顾笙9802 小时前
day12-数据结构力扣
数据结构·算法·leetcode
凌波粒2 小时前
LeetCode--454.四数相加 II(哈希表)
算法·leetcode·散列表