-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
+++ | ||
title = "ARTS 2024.07.20" | ||
date = 2024-07-20 | ||
|
||
[taxonomies] | ||
tags = ["ARTS"] | ||
+++ | ||
|
||
## Algorithm | ||
|
||
[2850. 将石头分散到网格图的最少移动次数 - 力扣(LeetCode)](https://leetcode.cn/problems/minimum-moves-to-spread-stones-over-grid/description/) | ||
|
||
empty表示空的格子,即目标。stones表示大于1的格子,同时记录可以移动的数量,深搜即可。尝试剪枝,效果不明显。官方题解里,是在stones里记录多个重复的格子,不单独计算数量。全排列 stones,empty不变,计算距离。 | ||
|
||
一篇[题解](https://leetcode.cn/problems/minimum-moves-to-spread-stones-over-grid/solutions/2435313/tong-yong-zuo-fa-zui-xiao-fei-yong-zui-d-iuw8/)里提到了最小费用最大流,维基百科链接:[最小费用最大流问题 - 维基百科,自由的百科全书 (wikipedia.org)](https://zh.wikipedia.org/wiki/%E6%9C%80%E5%B0%8F%E8%B4%B9%E7%94%A8%E6%9C%80%E5%A4%A7%E6%B5%81%E9%97%AE%E9%A2%98) | ||
|
||
```java | ||
class Solution { | ||
public int minimumMoves(int[][] grid) { | ||
List<int[]> empty = new ArrayList<>(9); | ||
List<int[]> stones = new ArrayList<>(4); | ||
|
||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
if (grid[i][j] == 0) { | ||
empty.add(new int[]{i, j}); | ||
} else if (grid[i][j] > 1) { | ||
stones.add(new int[]{i, j, grid[i][j] - 1}); | ||
} | ||
} | ||
} | ||
|
||
return choose(empty, stones, 0); | ||
} | ||
|
||
private int choose(List<int[]> empty, List<int[]> stones, int cur) { | ||
if (cur >= empty.size()) { | ||
return 0; | ||
} | ||
int[] focus = empty.get(cur); | ||
int size = stones.size(); | ||
int min = Integer.MAX_VALUE; | ||
for (int[] stone : stones) { | ||
if (stone[2] > 0) { | ||
int step = move(focus, stone); | ||
stone[2] -= 1; | ||
step += choose(empty, stones, cur + 1); | ||
stone[2] += 1; | ||
min = Math.min(min, step); | ||
} | ||
} | ||
return min; | ||
} | ||
|
||
private int move(int[] dest, int[] src) { | ||
return Math.abs(dest[0] - src[0]) + Math.abs(dest[1] - src[1]); | ||
} | ||
} | ||
``` | ||
|
||
## Review | ||
|
||
[Protobuf Field Masks | Pinkie Practices](https://pinkiepractices.com/posts/protobuf-field-masks/) | ||
|
||
关于 protobuf Field Masks 使用的一篇文章。对于 Field Masks 之前没有了解。Field Mask 利用了 field name,破坏了 protobuf 的兼容语义,不是好的设计,不推荐使用 | ||
|
||
## Tips | ||
|
||
## Share | ||
|
||
[CrowdStrike史诗级蓝屏,到底怎么破? (qq.com)](https://mp.weixin.qq.com/s?__biz=MzAxOTk3NTg5OQ==&mid=2247490735&idx=1&sn=e9acaf820be2b40fdd1fda0a875bab0b) | ||
|
||
7月19日,CrowdStirke 一次更新导致全球范围内windows大面积蓝屏 | ||
|
||
1. code review? | ||
2. 测试流程? | ||
3. 灰度发布? | ||
|
||
[Technical Details on July 19, 2024 Outage | CrowdStrike](https://www.crowdstrike.com/blog/technical-details-on-todays-outage/) |