【算法题】js 两人船和三人船的最小花费

      const getRes = (n, a, b, res = 0) => {
        if (a / 2 < b / 3) {
          res = Math.floor(n / 2) * a
          if (n & 1) res = Math.min(res + Math.min(a, b), res - a + b) // 奇数
        } else {
          res = Math.floor(n / 3) * b
          if (n % 3 == 1) res = Math.min(res + Math.min(a, b), res - b + 2 * a)
          else if (n % 3 == 2) res += Math.min(a, b)
        }
        return res
      }
      console.log(getRes(2, 20, 200)) // 20
      console.log(getRes(3, 20, 20)) // 20
      console.log(getRes(5, 40, 50)) // 90
原题链接 https://www.cnblogs.com/K2MnO4/p/14583900.html
全部评论

相关推荐

星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
05-22 09:23
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务