zoukankan      html  css  js  c++  java
  • leetcode1276

     1 class Solution:
     2     def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List[int]:
     3         tomato_low = cheeseSlices * 2
     4         tomato_high = cheeseSlices * 4
     5         if tomatoSlices % 2 == 1 or tomatoSlices < tomato_low or tomatoSlices > tomato_high:
     6             return []
     7         div1,res1 = (tomatoSlices - tomato_low) // 2,(tomatoSlices - tomato_low) % 2
     8         if res1 == 0:
     9             return [div1,cheeseSlices-div1]
    10         return []

    以 cheese为基础,
    假设全部都是 小的,则需要 2 * cheese 个tomato,记为 tomato_low
    假设全部都是 大的,则需要 4 * cheese 个tomato,记为 tomato_high

    先判断提供的tomato是否在这个区间内,
    如果不在这个区间内,则返回[]在这个区间内。

    本题实际是要在这个区间内,看是否能够查询到tomato。

    tomato_low与tomato_high都是偶数,如果tomato在[low,high]之间,并且也是偶数,则肯定能够满足条件。

    只需计算,tomato与low的商,就表示需要做几个huge型的汉堡,而high - tomato,就是small型汉堡的数量。

  • 相关阅读:
    Win10创意者更新秋季版激活秘籍
    将刷了Android的Lumia恢复为WP系统
    给Lumia 520/521/525/526/720刷Android系统
    DNS解析
    遍历对象目录
    PE注入
    利用NtCreateThreadEx注入
    利用CreateRemoteThread注入
    APC注入
    SetWindowHookEx()注入
  • 原文地址:https://www.cnblogs.com/asenyang/p/11965571.html
Copyright © 2011-2022 走看看