LeetCode 5276. 不浪费原料的汉堡制作方案 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,就请返回 []。
示例 : 输入:tomatoSlices = , cheeseSlices =
输出:[,]
解释:制作 个巨无霸汉堡和 个小皇堡需要 * + * = 片番茄和 + = 片奶酪。不会剩下原料。
示例 : 输入:tomatoSlices = , cheeseSlices =
输出:[]
解释:只制作小皇堡和巨无霸汉堡无法用光全部原料。
示例 : 输入:tomatoSlices = , cheeseSlices =
输出:[]
解释:制作 个巨无霸汉堡会剩下 片奶酪,制作 个小皇堡会剩下 片奶酪。
示例 : 输入:tomatoSlices = , cheeseSlices =
输出:[,]
示例 : 输入:tomatoSlices = , cheeseSlices =
输出:[,]
提示: <= tomatoSlices <= ^
<= cheeseSlices <= ^
算法1
鸡兔同笼 一个汉堡四条腿 另一个汉堡两条腿 四条腿两条腿汉堡都要吃一份奶酪
请问如何得出答案???
本题答案 要求番茄必须要在奶酪的 4 和 2的倍数之间 而且是双数
另外再假设所有材料都是以2份番茄 一份奶酪消耗 看看剩余的番茄
每剩余2份番茄就可以和之前2份番茄一份奶酪的材料 一并合成4份番茄 一份奶酪的组合
从而得出答案
class Solution {
public:
vector<int> ret;
vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {
if (tomatoSlices > cheeseSlices * || cheeseSlices * > tomatoSlices) return ret;
if (tomatoSlices % != ) return ret;
int count = cheeseSlices;
int left = tomatoSlices - cheeseSlices * ;
if (left == ) {
ret.push_back();
ret.push_back(count);
return ret;
}
int leftcount = left / ;
ret.push_back(leftcount);
ret.push_back(count - leftcount);
return ret;
}
};
LeetCode 5276. 不浪费原料的汉堡制作方案 Number of Burgers with No Waste of Ingredients的更多相关文章
- leetcode-165周赛-1276-不浪费原料的汉堡制作方案
题目描述: 自己的提交: class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List ...
- 【leetcode】1276. Number of Burgers with No Waste of Ingredients
题目如下: Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as ...
- 123457123456#0#-----com.threeapp.MakerHanBao01----儿童汉堡制作游戏
----com.threeapp.MakerHanBao01----儿童汉堡制作游戏
- 【js】Leetcode每日一题-停在原地的方案数
[js]Leetcode每日一题-停在原地的方案数 [题目描述] 有一个长度为 arrLen 的数组,开始有一个指针在索引 0 处. 每一步操作中,你可以将指针向左或向右移动 1 步,或者停在原地(指 ...
- LeetCode 171. Excel表列序号(Excel Sheet Column Number) 22
171. Excel表列序号 171. Excel Sheet Column Number 题目描述 给定一个 Excel 表格中的列名称,返回其相应的列序号. 每日一算法2019/5/25Day 2 ...
- leetcode解题报告(15):Third Maximum Number
描述 Given a non-empty array of integers, return the third maximum number in this array. If it does no ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number
题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number (easy)
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- leetcode第18题--Letter Combinations of a Phone Number
Problem: Given a digit string, return all possible letter combinations that the number could represe ...
随机推荐
- JVM(4) 类文件结构
一.实现“平台无关性” 字节码(ByteCode)存储格式和虚拟机是实现语言无关性的基础.Java虚拟机不和包括Java在内的任何语言绑定,它只与“Clas”文件这种特定的二进制文件格式所关联,Cla ...
- unity 导出模型
不论unity是否运行,到处其中的模型方法: 1.如下图建立相关文件目录,并建立如下脚本 2.脚本代码 using UnityEngine; using UnityEditor; using Syst ...
- fenby C语言 P26
指针 地址 类型+“*”+变量名=指针变量 int *p1;//指向整型变量的指针变量p1 float *p2;//指向浮点型变量的指针变量p2 char *p3;//指向字符型变量的指针变量p3 “ ...
- MySQL的统计信息学习总结
统计信息概念 MySQL统计信息是指数据库通过采样.统计出来的表.索引的相关信息,例如,表的记录数.聚集索引page个数.字段的Cardinality.....MySQL在生成执行计划时,需要根据索引 ...
- 自闭枪战C++
Player1: ad左右移动,w跳,jk发射子弹 Player2: 左右键左右移动,上键跳,23发射子弹 #include <bits/stdc++.h> #include <co ...
- nginx篇中级用法之反向代理(七层调度)
环境: 两台后端web,一台代理服务器 web1:eth0:192.168.2.100/24 httpd做一个web web2:eth0:192.168.2.200/24 httpd做一个we ...
- python中文件的基础操作
打开文件的三种方式: open(r'E:\学习日记\python\code\文件的简单操作.py') open('E:\\学习日记\\python\\code\\文件的简单操作.py') open(' ...
- Python 基础之re 模块
Python 基础之大话 re 在使用re模块中主要会用到一下几个方法: re.match() #从头匹配一个字符串 re.search() #浏览全部字符串,匹配第一个符合规则的字符串 re.fin ...
- yum.rpm一点点
rpm 1.rpm -qi查询包的详细信息 [root@centos7 tmp]# rpm -qi tree Name : tree Version : 1.6.0 Release : 10.el7 ...
- sqlite修改表、表字段等与sql server的不同之处
sqlite中只支持 ALTER TABLE 命令的 RENAME TABLE 和 ADD COLUMN. 其他类型的 ALTER TABLE 操作如 DROP COLUMN,ALTER COLUMN ...