From 1dec2ef90a319d2e317f35ba29d008dc88389c24 Mon Sep 17 00:00:00 2001 From: Edwardgudanyang Date: Sat, 7 Dec 2019 10:50:21 +0800 Subject: [PATCH 1/2] javaSolution A simple quadratic equation of one variable --- .../javaSolution | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution diff --git a/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution b/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution new file mode 100644 index 0000000000000..938b96c45010c --- /dev/null +++ b/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution @@ -0,0 +1,63 @@ +import java.util.ArrayList; +import java.util.List; + +//圣诞活动预热开始啦,汉堡店推出了全新的汉堡套餐。为了避免浪费原料,请你帮他们制定合适的制作计划。 +// +// 给你两个整数 tomatoSlices 和 cheeseSlices,分别表示番茄片和奶酪片的数目。不同汉堡的原料搭配如下: +// +// 巨无霸汉堡:4 片番茄和 1 片奶酪 +// 小皇堡:2 片番茄和 1 片奶酪 +// 请你以 [total_jumbo, total_small]([巨无霸汉堡总数,小皇堡总数])的格式返回恰当的制作方案,使得剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量都是 0。 +// +// 如果无法使剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量为 0,就请返回 []。 +// +//   +// +// 示例 1: +// +// 输入:tomatoSlices = 16, cheeseSlices = 7 +// 输出:[1,6] +// 解释:制作 1 个巨无霸汉堡和 6 个小皇堡需要 4*1 + 2*6 = 16 片番茄和 1 + 6 = 7 片奶酪。不会剩下原 +//示例 2: +// +// 输入:tomatoSlices = 17, cheeseSlices = 4 +// 输出:[] +// 解释:只制作小皇堡和巨无霸汉堡无法用光全部原料。 +// 示例 3: +// +// 输入:tomatoSlices = 4, cheeseSlices = 17 +// 输出:[] +// 解释:制作 1 个巨无霸汉堡会剩下 16 片奶酪,制作 2 个小皇堡会剩下 15 片奶酪。 +// 示例 4: +// +// 输入:tomatoSlices = 0, cheeseSlices = 0 +// 输出:[0,0] +// 示例 5: +// +// 输入:tomatoSlices = 2, cheeseSlices = 1 +// 输出:[0,1] +//提示: +// +// 0 <= tomatoSlices <= 10^7 +// 0 <= cheeseSlices <= 10^7 +public class no1276 { + public static List numOfBurgers(int tomatoSlices, int cheeseSlices) { + List burgers = new ArrayList<>(); + //巨无霸汉堡A,小皇堡B + + + if (tomatoSlices % 2 == 1 || tomatoSlices > cheeseSlices * 4 || cheeseSlices > tomatoSlices / 2) { + return burgers; + } + int A = (tomatoSlices-2*cheeseSlices)/2, B = cheeseSlices-A; + + burgers.add(A); + burgers.add(B); + return burgers; + } + + public static void main(String args[]) { + System.out.println(numOfBurgers(16, 7)); + } +} + From 84266ee05b2923ce8806aa6202262c04dae68d81 Mon Sep 17 00:00:00 2001 From: Edwardgudanyang Date: Sat, 7 Dec 2019 11:35:54 +0800 Subject: [PATCH 2/2] Update javaSolution --- .../javaSolution | 54 +------------------ 1 file changed, 2 insertions(+), 52 deletions(-) diff --git a/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution b/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution index 938b96c45010c..4fa1bdfc0bba0 100644 --- a/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution +++ b/solution/1276.Number of Burgers with No Waste of Ingredients/javaSolution @@ -1,63 +1,13 @@ -import java.util.ArrayList; -import java.util.List; - -//圣诞活动预热开始啦,汉堡店推出了全新的汉堡套餐。为了避免浪费原料,请你帮他们制定合适的制作计划。 -// -// 给你两个整数 tomatoSlices 和 cheeseSlices,分别表示番茄片和奶酪片的数目。不同汉堡的原料搭配如下: -// -// 巨无霸汉堡:4 片番茄和 1 片奶酪 -// 小皇堡:2 片番茄和 1 片奶酪 -// 请你以 [total_jumbo, total_small]([巨无霸汉堡总数,小皇堡总数])的格式返回恰当的制作方案,使得剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量都是 0。 -// -// 如果无法使剩下的番茄片 tomatoSlices 和奶酪片 cheeseSlices 的数量为 0,就请返回 []。 -// -//   -// -// 示例 1: -// -// 输入:tomatoSlices = 16, cheeseSlices = 7 -// 输出:[1,6] -// 解释:制作 1 个巨无霸汉堡和 6 个小皇堡需要 4*1 + 2*6 = 16 片番茄和 1 + 6 = 7 片奶酪。不会剩下原 -//示例 2: -// -// 输入:tomatoSlices = 17, cheeseSlices = 4 -// 输出:[] -// 解释:只制作小皇堡和巨无霸汉堡无法用光全部原料。 -// 示例 3: -// -// 输入:tomatoSlices = 4, cheeseSlices = 17 -// 输出:[] -// 解释:制作 1 个巨无霸汉堡会剩下 16 片奶酪,制作 2 个小皇堡会剩下 15 片奶酪。 -// 示例 4: -// -// 输入:tomatoSlices = 0, cheeseSlices = 0 -// 输出:[0,0] -// 示例 5: -// -// 输入:tomatoSlices = 2, cheeseSlices = 1 -// 输出:[0,1] -//提示: -// -// 0 <= tomatoSlices <= 10^7 -// 0 <= cheeseSlices <= 10^7 -public class no1276 { - public static List numOfBurgers(int tomatoSlices, int cheeseSlices) { +public List numOfBurgers(int tomatoSlices, int cheeseSlices) { List burgers = new ArrayList<>(); //巨无霸汉堡A,小皇堡B - - if (tomatoSlices % 2 == 1 || tomatoSlices > cheeseSlices * 4 || cheeseSlices > tomatoSlices / 2) { return burgers; } int A = (tomatoSlices-2*cheeseSlices)/2, B = cheeseSlices-A; - burgers.add(A); burgers.add(B); return burgers; - } - - public static void main(String args[]) { - System.out.println(numOfBurgers(16, 7)); - } } +