[leetcode] 1276. Number of Burgers with No Waste of Ingredients

网友投稿 771 2022-08-23

[leetcode] 1276. Number of Burgers with No Waste of Ingredients

Description

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 = 7Output: [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 = 4Output: []Explantion: There will be no way to use all ingredients to make small and jumbo burgers.

Example 3:

Input: tomatoSlices = 4, cheeseSlices = 17Output: []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 = 0Output: [0,0]

Example 5:

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

Constraints:

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

分析

题目的意思是:给定汉堡包的原料做汉堡包,问能不能刚好用完原料。我一看就是一个初中数学题,设能做出x1个Jumbo Burger,x2个Small Burger,y1是tomatoSlices的数量,y2是cheeseSlices的数量则:

4x1+x2=y1x1+x2=y2

求解出来:x1=(y1-y2)/2 x2=y2-x1 然后判断x1和x2是不是正整数就行了,哈哈,终于把初中数学用上了

代码

class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]: y1=tomatoSlices y2=cheeseSlices t=y1-2*y2 if(t>=0 and t%2==0): if(y2-t//2>=0): return [t//2,y2-t//2] return []

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Android Studio常用插件(android studio)
下一篇:[leetcode] 791. Custom Sort String
相关文章

 发表评论

暂时没有评论,来抢沙发吧~