{"id":5908,"date":"2019-12-01T23:00:13","date_gmt":"2019-12-02T07:00:13","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=5908"},"modified":"2019-12-01T23:00:52","modified_gmt":"2019-12-02T07:00:52","slug":"1276-number-of-burgers-with-no-waste-of-ingredients","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/math\/1276-number-of-burgers-with-no-waste-of-ingredients\/","title":{"rendered":"\u82b1\u82b1\u9171 1276. Number of Burgers with No Waste of Ingredients"},"content":{"rendered":"\n<p>Given two integers&nbsp;<code>tomatoSlices<\/code>&nbsp;and&nbsp;<code>cheeseSlices<\/code>. The ingredients of different burgers are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Jumbo Burger:<\/strong>&nbsp;4 tomato slices&nbsp;and 1 cheese slice.<\/li><li><strong>Small Burger:<\/strong>&nbsp;2 Tomato slices&nbsp;and 1 cheese slice.<\/li><\/ul>\n\n\n\n<p>Return&nbsp;<code>[total_jumbo, total_small]<\/code>&nbsp;so that the number of remaining&nbsp;<code>tomatoSlices<\/code>&nbsp;equal to 0 and the number of remaining&nbsp;<code>cheeseSlices<\/code>&nbsp;equal to 0. If it is not possible to make the remaining&nbsp;<code>tomatoSlices<\/code>&nbsp;and&nbsp;<code>cheeseSlices<\/code>&nbsp;equal to 0 return&nbsp;<code>[]<\/code>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> tomatoSlices = 16, cheeseSlices = 7\n<strong>Output:<\/strong> [1,6]\n<strong>Explantion:<\/strong> 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.\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> tomatoSlices = 17, cheeseSlices = 4\n<strong>Output:<\/strong> []\n<strong>Explantion:<\/strong> There will be no way to use all ingredients to make small and jumbo burgers.\n<\/pre>\n\n\n\n<p><strong>Example 3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> tomatoSlices = 4, cheeseSlices = 17\n<strong>Output:<\/strong> []\n<strong>Explantion:<\/strong> Making 1 jumbo burger there will be 16 cheese remaining and making 2 small burgers there will be 15 cheese remaining.\n<\/pre>\n\n\n\n<p><strong>Example 4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> tomatoSlices = 0, cheeseSlices = 0\n<strong>Output:<\/strong> [0,0]\n<\/pre>\n\n\n\n<p><strong>Example 5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> tomatoSlices = 2, cheeseSlices = 1\n<strong>Output:<\/strong> [0,1]\n<\/pre>\n\n\n\n<p><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>0 &lt;= tomatoSlices &lt;= 10^7<\/code><\/li><li><code>0 &lt;= cheeseSlices &lt;= 10^7<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution: Math<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(1)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"C++\">\n\/\/ Author: Huahua\nclass Solution {\npublic:\n  vector<int> numOfBurgers(int T, int C) {\n    \/\/ Jumbo = x, small = y\n    \/\/ 4x + 2y = T\n    \/\/ x + y = C\n    \/\/ x = (T - 2C) \/ 2\n    int x = T \/ 2 - C;\n    int y = C - x;\n    if (4 * x + 2 * y == T && x >= 0 && y >= 0) return {x, y};\n    return {};\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given two integers&nbsp;tomatoSlices&nbsp;and&nbsp;cheeseSlices. The ingredients of different burgers are as follows: Jumbo Burger:&nbsp;4 tomato slices&nbsp;and 1 cheese slice. Small Burger:&nbsp;2 Tomato slices&nbsp;and 1 cheese slice.&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[31,177,92],"class_list":["post-5908","post","type-post","status-publish","format-standard","hentry","category-math","tag-math","tag-medium","tag-o1","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=5908"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5908\/revisions"}],"predecessor-version":[{"id":5910,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5908\/revisions\/5910"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=5908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=5908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=5908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}