From 29a23593dd2df2d665a05d46e9473ff8427c8dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A9=E8=BE=95=E9=BE=99=E5=84=BF?= Date: Thu, 3 Mar 2022 21:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=A8=E8=B5=9B282?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contest/y2022/m2/week/Solution282.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/contest/y2022/m2/week/Solution282.java diff --git a/src/main/java/contest/y2022/m2/week/Solution282.java b/src/main/java/contest/y2022/m2/week/Solution282.java new file mode 100644 index 0000000..e7d9e30 --- /dev/null +++ b/src/main/java/contest/y2022/m2/week/Solution282.java @@ -0,0 +1,90 @@ +package contest.y2022.m2.week; + +import com.code.leet.entiy.TwoArray; + +import java.util.*; + +/** + * @description: + * @author: Administrator + * @date: 2021/8/22-10:29 + */ +public class Solution282 { + public static void main(String[] args) { + Solution282 solution = new Solution282(); + TwoArray twoArray = new TwoArray("[[2,3],[3,4]]", true); + System.out.println(solution.minimumFinishTime(twoArray.getArr(), 5, 4)); + } + + public int prefixCount(String[] words, String pref) { + int count = 0; + for (String word : words) { + if (word.startsWith(pref)) { + count++; + } + } + return count; + } + + public int minSteps(String s, String t) { + int[] chs = new int[26]; + for (int i = 0; i < s.length(); i++) { + chs[s.charAt(i) - 'a']++; + } + for (int i = 0; i < t.length(); i++) { + chs[t.charAt(i) - 'a']--; + } + int count = 0; + for (int i = 0; i < 26; i++) { + if (chs[i] < 0) { + count -= chs[i]; + } else if (chs[i] > 0) { + count += chs[i]; + } + } + return count; + } + + public long minimumTime(int[] time, int totalTrips) { + long min = 1; + long max = (long) time[time.length - 1] * totalTrips; + while (min < max) { + long mid = (min + max) / 2; + long temp = 0; + for (int j : time) { + temp += mid / j; + } + if (temp < totalTrips) { + min = mid + 1; + } else { + max = mid; + } + } + return min; + } + + public int minimumFinishTime(int[][] tires, int changeTime, int numLaps) { + Queue queue = new PriorityQueue<>(); + + int[][] arrs = new int[tires.length][numLaps]; + for (int i = 0; i < numLaps; i++) { + Queue temp = new PriorityQueue<>(); + for (int j = 0; j < tires.length; j++) { + if (i == 0) { + arrs[j][0] = tires[j][0]; + temp.add(tires[j][0]); + } else { + int mul = queue.peek(); + arrs[j][i] = Math.min(mul + changeTime + tires[j][0], tires[j][0] * tires[j][1] + arrs[j][i - 1]); + temp.add(arrs[j][i]); + } + } + queue = temp; + } + int result = arrs[0][numLaps - 1]; + for (int i = 1; i < tires.length; i++) { + result = Math.min(result, arrs[i][numLaps - 1]); + } + return result; + } +}