Cố Trường Ca
Senior Member
Xem tệp đính kèm 2658839 có mà nhỉ
Xem tệp đính kèm 2658839 có mà nhỉ
Tụi nó mới fix có lại streak hay sao ấy, mà bài thì vẫn trùng ko đổi.
Lại ăn 1 cái badge tháng![]()
Quyết tâm ko nghỉ ngày nào trong năm nay

chủ quán cho xin phần cơm thêm, nay chưa code dc bài nào ngứa ngáy quáQuyết tâm ko nghỉ ngày nào trong năm nay![]()
chủ quán cho xin phần cơm thêm, nay chưa code dc bài nào ngứa ngáy quá
thím học tiếng anh thế nào lên được 7.5 thế, share kinh nghiệm được không

Mình đâu có Ielts gì đâu fencethím học tiếng anh thế nào lên được 7.5 thế, share kinh nghiệm được không![]()

làm dc bài med, nhưng vẫn phải mò xem hint có trùng ý tưởng ko mới dám implement, không dc như mấy bác gặp là múc, đụng là trụng
class Solution {
public int minChanges(int[] nums, int k) {
int n= nums.length;
Map<Integer, Integer> freq = new HashMap();
int[] maxDiff = new int[k+1];
for(int i =0 ; i < n/2;i++){
int diff = Math.abs(nums[i]-nums[n-1-i]);
freq.put(diff, freq.getOrDefault(diff,0)+1);
int greater = Math.max(nums[i],nums[n-1-i]);
int smaller = nums[i]+nums[n-1-i] - greater;
maxDiff[Math.max(greater - 0, k - smaller)]++;
}
for(int i = 1; i<=k;i++){
maxDiff[i] +=maxDiff[i-1];
}
int res =n;
for(int x:freq.keySet()){
int changeBoth=x==0?0:maxDiff[x-1];
int changeOne =n/2 - freq.get(x);
res=Math.min(res,changeOne + changeBoth);
}
return res;
}
}
public class Solution {
public double MaxProbability(int n, int[][] edges, double[] succProb, int start_node, int end_node)
{
Dictionary<int, Node> graph = new();
for (int i = 0; i < edges.Length; i++)
{
graph.TryGetValue(edges[i][0], out var node1);
if (node1 == null)
{
node1 = new();
node1.id = edges[i][0];
graph.Add(node1.id, node1);
}
graph.TryGetValue(edges[i][1], out var node2);
if (node2 == null)
{
node2 = new();
node2.id = edges[i][1];
graph.Add(node2.id, node2);
}
double rate = succProb[i];
node1.neighbors.Add(node2.id);
node1.pathCosts.Add(rate);
node2.neighbors.Add(node1.id);
node2.pathCosts.Add(rate);
}
PriorityQueue<int, double> q = new();
Dictionary<int, double> distance = new();
q.Enqueue(start_node, -1);
distance.Add(start_node, 1);
while (q.Count > 0)
{
int nodeId = q.Dequeue();
graph.TryGetValue(nodeId, out var currentNode);
if (currentNode == null)
{
return 0;
}
distance.TryGetValue(nodeId, out double currentCost);
if (nodeId == end_node)
{
return currentCost;
}
for (int i = 0; i < currentNode.neighbors.Count; i++)
{
int neighborId = currentNode.neighbors[i];
distance.TryGetValue(neighborId, out double recorded);
double newCost = currentCost * currentNode.pathCosts[i];
if (newCost <= recorded)
{
continue;
}
distance[neighborId] = newCost;
q.Enqueue(neighborId, -newCost);
}
}
return 0;
}
public class Node
{
public int id;
public List<int> neighbors = new();
public List<double> pathCosts = new();
}
}
câu này mới ra hôm t5 chứ đâu bácC#:public class Solution { public double MaxProbability(int n, int[][] edges, double[] succProb, int start_node, int end_node) { Dictionary<int, Node> graph = new(); for (int i = 0; i < edges.Length; i++) { graph.TryGetValue(edges[i][0], out var node1); if (node1 == null) { node1 = new(); node1.id = edges[i][0]; graph.Add(node1.id, node1); } graph.TryGetValue(edges[i][1], out var node2); if (node2 == null) { node2 = new(); node2.id = edges[i][1]; graph.Add(node2.id, node2); } double rate = succProb[i]; node1.neighbors.Add(node2.id); node1.pathCosts.Add(rate); node2.neighbors.Add(node1.id); node2.pathCosts.Add(rate); } PriorityQueue<int, double> q = new(); Dictionary<int, double> distance = new(); q.Enqueue(start_node, -1); distance.Add(start_node, 1); while (q.Count > 0) { int nodeId = q.Dequeue(); graph.TryGetValue(nodeId, out var currentNode); if (currentNode == null) { return 0; } distance.TryGetValue(nodeId, out double currentCost); if (nodeId == end_node) { return currentCost; } for (int i = 0; i < currentNode.neighbors.Count; i++) { int neighborId = currentNode.neighbors[i]; distance.TryGetValue(neighborId, out double recorded); double newCost = currentCost * currentNode.pathCosts[i]; if (newCost <= recorded) { continue; } distance[neighborId] = newCost; q.Enqueue(neighborId, -newCost); } } return 0; } public class Node { public int id; public List<int> neighbors = new(); public List<double> pathCosts = new(); } }
Tiếng Anh học dễ mà, ra trung tâm học kết hợp xem film.Nhớ nhầm đối tượng à, mà không có ielts sao qua được mỹ đế![]()
class Solution {
/**
* @param Integer[] $original
* @param Integer $m
* @param Integer $n
* @return Integer[][]
*/
function construct2DArray($original, $m, $n) {
if (count($original) != $m*$n) return [];
$offset = 0;
$ans = [];
for ($r = 0; $r < $m; $r++) {
$ans[] = array_slice($original, $offset, $n);
$offset += $n;
}
return $ans;
}
}
class Solution {
public int[][] construct2DArray(int[] original, int m, int n) {
if(original.length != m*n) return new int[0][0];
int[][] res = new int[m][n];
int ind = 0;
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
res[i][j] = original[ind++];
}
}
return res;
}
}