zoukankan      html  css  js  c++  java
  • LeetCode 1276. 不浪费原料的汉堡制作方案 Number of Burgers with No Waste of Ingredients

    地址 https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients/

    目描述
    圣诞活动预热开始啦,汉堡店推出了全新的汉堡套餐。为了避免浪费原料,请你帮他们制定合适的制作计划。

    给你两个整数 tomatoSlices 和 cheeseSlices,分别表示番茄片和奶酪片的数目。不同汉堡的原料搭配如下:

    巨无霸汉堡:4 片番茄和 1 片奶酪
    小皇堡:2 片番茄和 1 片奶酪
    请你以 [total_jumbo, total_small]([巨无霸汉堡总数,小皇堡总数])的格式返回恰当的制作方案,使得剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量都是 0。

    如果无法使剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量为 0,就请返回 []。

    示例 1:
    
    输入:tomatoSlices = 16, cheeseSlices = 7
    输出:[1,6]
    解释:制作 1 个巨无霸汉堡和 6 个小皇堡需要 4*1 + 2*6 = 16 片番茄和 1 + 6 = 7 片奶酪。不会剩下原料。
    示例 2:
    
    输入:tomatoSlices = 17, cheeseSlices = 4
    输出:[]
    解释:只制作小皇堡和巨无霸汉堡无法用光全部原料。
    示例 3:
    
    输入:tomatoSlices = 4, cheeseSlices = 17
    输出:[]
    解释:制作 1 个巨无霸汉堡会剩下 16 片奶酪,制作 2 个小皇堡会剩下 15 片奶酪。
    示例 4:
    
    输入:tomatoSlices = 0, cheeseSlices = 0
    输出:[0,0]
    示例 5:
    
    输入:tomatoSlices = 2, cheeseSlices = 1
    输出:[0,1]
     
    
    提示:
    
    0 <= tomatoSlices <= 10^7
    0 <= cheeseSlices <= 10^7

    算法1
    鸡兔同笼 一个汉堡四条腿 另一个汉堡两条腿 四条腿两条腿汉堡都要吃一份奶酪
    请问如何得出答案???

    本题答案 要求番茄必须要在奶酪的 4 和 2的倍数之间 而且是双数
    另外再假设所有材料都是以2份番茄 一份奶酪消耗 看看剩余的番茄
    每剩余2份番茄就可以和之前2份番茄一份奶酪的材料 一并合成4份番茄 一份奶酪的组合
    从而得出答案

     1 class Solution {
     2 public:
     3 
     4     vector<int> ret;
     5 vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
     6     if (tomatoSlices > cheeseSlices * 4  || cheeseSlices * 2 > tomatoSlices)  return ret;
     7     if (tomatoSlices % 2 != 0) return ret;
     8 
     9     int count = cheeseSlices;
    10     int left = tomatoSlices - cheeseSlices * 2;
    11     if (left == 0) {
    12         ret.push_back(0);
    13         ret.push_back(count);
    14         return ret;
    15     }
    16 
    17     int leftcount = left / 2;
    18     ret.push_back(leftcount);
    19     ret.push_back(count - leftcount);
    20     return ret;
    21 }
    22 
    23 };
    View Code
    作 者: itdef
    欢迎转帖 请保持文本完整并注明出处
    技术博客 http://www.cnblogs.com/itdef/
    B站算法视频题解
    https://space.bilibili.com/18508846
    qq 151435887
    gitee https://gitee.com/def/
    欢迎c c++ 算法爱好者 windows驱动爱好者 服务器程序员沟通交流
    如果觉得不错,欢迎点赞,你的鼓励就是我的动力
    阿里打赏 微信打赏
  • 相关阅读:
    css换行
    VC include 路径解析 冷夜
    DirectxDraw学习笔记 冷夜
    winmain窗口代码 冷夜
    DirectDraw 常用功能代码记录 冷夜
    C/C++ 内存分配方式,堆区,栈区,new/delete/malloc/free 冷夜
    BMP文件结构 冷夜
    管道流
    打印流
    字符编码
  • 原文地址:https://www.cnblogs.com/itdef/p/11968092.html
Copyright © 2011-2022 走看看