kk
This commit is contained in:
50
src/main/java/com/dota/binarySearch/_2861/Solution.java
Normal file
50
src/main/java/com/dota/binarySearch/_2861/Solution.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package com.dota.binarySearch._2861;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Solution().maxNumberOfAlloys(1,2,24308609, List.of(List.of(40), List.of(88)),List.of(82685338),List.of(2));
|
||||||
|
}
|
||||||
|
public int maxNumberOfAlloys(int n, int k, int budget, List<List<Integer>> composition, List<Integer> stock, List<Integer> cost) {
|
||||||
|
int max = 0;
|
||||||
|
for (Integer i : stock) {
|
||||||
|
max = Math.max(max, i);
|
||||||
|
}
|
||||||
|
int i = 0, j = budget + 1 + max;
|
||||||
|
while (i + 1 < j) {
|
||||||
|
int mid = i + (j - i) / 2;
|
||||||
|
if (check(mid, budget, composition, stock, cost)) {
|
||||||
|
i = mid;
|
||||||
|
} else {
|
||||||
|
j = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主要看钱够不够造k份合金
|
||||||
|
boolean check(int k, long budget, List<List<Integer>> composition, List<Integer> stock, List<Integer> cost) {
|
||||||
|
long t = budget;
|
||||||
|
for (List<Integer> integers : composition) {
|
||||||
|
budget = t;
|
||||||
|
for (int j = 0; j < integers.size(); j++) {
|
||||||
|
if ((long)stock.get(j) >= (long) k * integers.get(j)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
long a = (long) k * integers.get(j) - stock.get(j);
|
||||||
|
long b = a * cost.get(j);
|
||||||
|
if (budget < b) {
|
||||||
|
budget = - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
budget -= b;
|
||||||
|
}
|
||||||
|
if (budget >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/com/dota/stack/_3170/Solution.java
Normal file
31
src/main/java/com/dota/stack/_3170/Solution.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.dota.stack._3170;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public String clearStars(String s) {
|
||||||
|
var stack = new PriorityQueue<Integer>((a,b)->{
|
||||||
|
if (s.charAt(a)==s.charAt(b)) {
|
||||||
|
return b - a;
|
||||||
|
}
|
||||||
|
return s.charAt(a) - s.charAt(b);
|
||||||
|
});
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
if (s.charAt(i) == '*') {
|
||||||
|
stack.poll();
|
||||||
|
} else {
|
||||||
|
stack.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var set = new HashSet<>(stack);
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
if (set.contains(i)) {
|
||||||
|
sb.append(s.charAt(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user