前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【LeetCode第 165 场周赛】不浪费原料的汉堡制作方案

【LeetCode第 165 场周赛】不浪费原料的汉堡制作方案

作者头像
韩旭051
发布2019-12-03 01:18:14
3830
发布2019-12-03 01:18:14
举报
文章被收录于专栏:刷题笔记

版权声明:本文为博主原创文章,遵循 CC 4.0 BY 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/shiliang97/article/details/103334095

5276. Number of Burgers with No Waste of Ingredients

Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:

Jumbo Burger: 4 tomato slices and 1 cheese slice. Small Burger: 2 Tomato slices and 1 cheese slice. Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].

Example 1:

Input: tomatoSlices = 16, cheeseSlices = 7 Output: [1,6] Explantion: To make one jumbo burger and 6 small burgers we need 4*1 + 2*6 = 16 tomato and 1 + 6 = 7 cheese. There will be no remaining ingredients. Example 2:

Input: tomatoSlices = 17, cheeseSlices = 4 Output: [] Explantion: There will be no way to use all ingredients to make small and jumbo burgers. Example 3:

Input: tomatoSlices = 4, cheeseSlices = 17 Output: [] Explantion: Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining. Example 4:

Input: tomatoSlices = 0, cheeseSlices = 0 Output: [0,0] Example 5:

Input: tomatoSlices = 2, cheeseSlices = 1 Output: [0,1]

Constraints:

0 <= tomatoSlices <= 10^7 0 <= cheeseSlices <= 10^7

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

外国版鸡兔同笼?

第一种 4个A,一个B

第二种 2个A,一个B

假设全是第二种就要 2B个A

A-2B就是多出来的,(A-2B)/2就是第一种个数

A-(A-2B)/2就是第二种个数

如果减法出现了负数说明无解

代码语言:javascript
复制
class Solution {
public:
    vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
        vector<int> v;
        int a=(tomatoSlices-cheeseSlices*2);
        if(a%2==0&&a>=0&&cheeseSlices>=a/2){
            a=a/2;
            v.push_back(a);
            v.push_back(cheeseSlices-a);
        }else {
            return v;
        }return v;
        
    }
};
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/12/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 外国版鸡兔同笼?
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档