Bug fixes and improvements (#1078)

* Fix the logo in the en version

* Optimize header color and fix body background color

* Update theme switch's name

* Fix backfrop-filter on Safari

* Update some animation's file name for adding egde when cropping

* Re-count the comments number

* A bug fix in n_queens_problem.md
This commit is contained in:
Yudong Jin
2024-02-14 18:37:18 +08:00
committed by GitHub
parent 5f82a86bd6
commit e813b5a0fa
49 changed files with 94 additions and 58 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

-36
View File
@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.48 59.28">
<defs>
<style>
.cls-1 {
fill: #2aa996;
}
.cls-1, .cls-2 {
stroke-width: 0px;
}
.cls-2 {
fill: #21c8b8;
}
</style>
</defs>
<g id="_layer_1" data-name="layer 1">
<path class="cls-2" d="m5.02,34.2c-1.67,8.36-3.34,16.72-5.02,25.08h5.02c1.67-8.36,3.34-16.72,5.02-25.08h-5.02Z"/>
<path class="cls-2" d="m25.22,49.25c.33-1.67.67-3.34,1-5.02H9.07c-.33,1.67-.67,3.34-1,5.02h17.16Z"/>
<path class="cls-2" d="m30.16,54.27c.33-1.67.67-3.34,1-5.02h7.05c.33-1.67.67-3.34,1-5.02h-7.05c.33-1.67.67-3.34,1-5.02h7.05c.33-1.67.67-3.34,1-5.02-4.02,0-8.04,0-12.06,0-1.67,8.36-3.34,16.72-5.02,25.08,4.03,0,8.06,0,12.09,0,.33-1.67.67-3.34,1-5.02h-7.07Z"/>
<path class="cls-2" d="m93.39,34.2h-16.56s0,0,0,0c-.01.04-.92.05-3.5,0-1.67,8.36-3.34,16.72-5.02,25.08h20.07c1.67-8.36,3.34-16.72,5.02-25.08Zm-19.06,20.07c1-5.02,2.01-10.03,3.01-15.05h10.03c-1,5.02-2.01,10.03-3.01,15.05h-10.03Z"/>
<path class="cls-2" d="m44.23,54.27h0c1.34-6.69,2.68-13.38,4.01-20.07h-5.02c-1.67,8.36-3.34,16.72-5.02,25.08h4.01c3.02,0,6.04,0,9.06,0,.33-1.67.67-3.34,1-5.02h-8.05Z"/>
<path class="cls-2" d="m59.29,54.27h0c1.34-6.69,2.68-13.38,4.01-20.07h-5.02c-1.67,8.36-3.34,16.72-5.02,25.08,4.36,0,8.71,0,13.07,0,.33-1.67.67-3.34,1-5.02h-8.05Z"/>
<path class="cls-1" d="m16.89.07h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.01c1-5.02,2.01-10.03,3.01-15.05Z"/>
<path class="cls-1" d="m34.32,33.21c1.14-5.69,2.27-11.38,3.41-17.07H8.65c-1.13,5.69-2.27,11.38-3.4,17.07h29.07Zm-21.64-12.06h19.03c-.07.34-.13.67-.2,1.01H12.48c.07-.34.13-.67.2-1.01Zm-1.21,6.03h19.03c-.07.34-.13.67-.2,1.01H11.27c.07-.34.13-.67.2-1.01Z"/>
<path class="cls-1" d="m28.93,15.12c1-5.02,2.01-10.03,3.01-15.05h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.01Z"/>
<path class="cls-1" d="m24.92,5.09c.33-1.67.67-3.34,1-5.02h-8.03c-.33,1.67-.67,3.34-1,5.02h8.03Z"/>
<path class="cls-1" d="m121.48,15.04s.5-2.49.5-2.51c.17-.84.33-1.67.5-2.51h-11.33c.66-3.34,1.33-6.68,1.99-10.02h-5.02c-.67,3.34-1.34,6.68-2,10.02h-7.02c-.33,1.67-.67,3.34-1,5.02h7.03s0,0,0,.01h.01c-.07.33-.13.67-.2,1h-7.07c-.33,1.67-.67,3.34-1,5.02h4.25c-2.57,12.74-5.14,25.48-7.7,38.22,6.4,0,12.8,0,19.21,0l5.07-25.08h-5.03c-1.35,6.69-2.71,13.38-4.06,20.07h-9.13c2.22-11.07,4.44-22.13,6.66-33.2h14.1c.33-1.67.67-3.34,1-5.02h-11.28c.07-.34.13-.67.2-1.01h11.33Z"/>
<path class="cls-1" d="m16.87,6.12c.6,3,1.2,6,1.8,9h4.23c-.6-3-1.2-6-1.8-9h-4.24Z"/>
<path class="cls-1" d="m97,16.06h-5.02c-1.13,5.69-2.27,11.38-3.4,17.06h5.01c1.13-5.69,2.27-11.38,3.4-17.06Z"/>
<path class="cls-1" d="m100.2,0h-5.02c-1,5.02-2.01,10.03-3.01,15.05h5.03c1-5.02,2-10.03,3-15.05Z"/>
<path class="cls-1" d="m39.97,5.09c.33-1.67.67-3.34,1-5.02h-8.03c-.33,1.67-.67,3.34-1,5.02h8.03Z"/>
<path class="cls-1" d="m31.92,6.12c.6,3,1.2,6,1.8,9h4.23c-.6-3-1.2-6-1.8-9h-4.24Z"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

@@ -44,6 +44,6 @@
[file]{n_queens}-[class]{}-[func]{n_queens}
```
逐行放置 $n$ 次,考虑列约束,则从第一行到最后一行分别有 $n$、$n-1$、$\dots$、$2$、$1$ 个选择,**因此时间复杂度为 $O(n!)$** 。实际上,根据对角线约束的剪枝也能够大幅缩小搜索空间,因而搜索效率往往优于以上时间复杂度。
逐行放置 $n$ 次,考虑列约束,则从第一行到最后一行分别有 $n$、$n-1$、$\dots$、$2$、$1$ 个选择,使用 $O(n!)$ 时间;当保存解时,需要复制矩阵 `state` 并添加进 `res` ,复制操作使用 $O(n^2)$ 时间;因此总体时间复杂度为 $O(n! \cdot n^2)$ 。实际上,根据对角线约束的剪枝也能够大幅缩小搜索空间,因而搜索效率往往优于以上时间复杂度。
数组 `state` 使用 $O(n^2)$ 空间,数组 `cols``diags1``diags2` 皆使用 $O(n)$ 空间。最大递归深度为 $n$ ,使用 $O(n)$ 栈帧空间。因此,**空间复杂度为 $O(n^2)$** 。
@@ -47,7 +47,7 @@
至此,我们就得到了下图所示的二维 $dp$ 矩阵,其尺寸与输入网格 $grid$ 相同。
![状态定义与 dp 表](dp_solution_pipeline.assets/min_path_sum_solution_step1.png)
![状态定义与 dp 表](dp_solution_pipeline.assets/min_path_sum_solution_state_definition.png)
!!! note
@@ -65,7 +65,7 @@ $$
dp[i, j] = \min(dp[i-1, j], dp[i, j-1]) + grid[i, j]
$$
![最优子结构与状态转移方程](dp_solution_pipeline.assets/min_path_sum_solution_step2.png)
![最优子结构与状态转移方程](dp_solution_pipeline.assets/min_path_sum_solution_state_transition.png)
!!! note
@@ -79,7 +79,7 @@ $$
如下图所示,由于每个格子是由其左方格子和上方格子转移而来,因此我们使用循环来遍历矩阵,外循环遍历各行,内循环遍历各列。
![边界条件与状态转移顺序](dp_solution_pipeline.assets/min_path_sum_solution_step3.png)
![边界条件与状态转移顺序](dp_solution_pipeline.assets/min_path_sum_solution_initial_state.png)
!!! note

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

+10 -10
View File
@@ -12,19 +12,19 @@
- **初始化**:传入 $n$ 个顶点,初始化长度为 $n$ 的顶点列表 `vertices` ,使用 $O(n)$ 时间;初始化 $n \times n$ 大小的邻接矩阵 `adjMat` ,使用 $O(n^2)$ 时间。
=== "初始化邻接矩阵"
![邻接矩阵的初始化、增删边、增删顶点](graph_operations.assets/adjacency_matrix_initialization.png)
![邻接矩阵的初始化、增删边、增删顶点](graph_operations.assets/adjacency_matrix_step1_initialization.png)
=== "添加边"
![adjacency_matrix_add_edge](graph_operations.assets/adjacency_matrix_add_edge.png)
![adjacency_matrix_add_edge](graph_operations.assets/adjacency_matrix_step2_add_edge.png)
=== "删除边"
![adjacency_matrix_remove_edge](graph_operations.assets/adjacency_matrix_remove_edge.png)
![adjacency_matrix_remove_edge](graph_operations.assets/adjacency_matrix_step3_remove_edge.png)
=== "添加顶点"
![adjacency_matrix_add_vertex](graph_operations.assets/adjacency_matrix_add_vertex.png)
![adjacency_matrix_add_vertex](graph_operations.assets/adjacency_matrix_step4_add_vertex.png)
=== "删除顶点"
![adjacency_matrix_remove_vertex](graph_operations.assets/adjacency_matrix_remove_vertex.png)
![adjacency_matrix_remove_vertex](graph_operations.assets/adjacency_matrix_step5_remove_vertex.png)
以下是基于邻接矩阵表示图的实现代码:
@@ -43,19 +43,19 @@
- **初始化**:在邻接表中创建 $n$ 个顶点和 $2m$ 条边,使用 $O(n + m)$ 时间。
=== "初始化邻接表"
![邻接表的初始化、增删边、增删顶点](graph_operations.assets/adjacency_list_initialization.png)
![邻接表的初始化、增删边、增删顶点](graph_operations.assets/adjacency_list_step1_initialization.png)
=== "添加边"
![adjacency_list_add_edge](graph_operations.assets/adjacency_list_add_edge.png)
![adjacency_list_add_edge](graph_operations.assets/adjacency_list_step2_add_edge.png)
=== "删除边"
![adjacency_list_remove_edge](graph_operations.assets/adjacency_list_remove_edge.png)
![adjacency_list_remove_edge](graph_operations.assets/adjacency_list_step3_remove_edge.png)
=== "添加顶点"
![adjacency_list_add_vertex](graph_operations.assets/adjacency_list_add_vertex.png)
![adjacency_list_add_vertex](graph_operations.assets/adjacency_list_step4_add_vertex.png)
=== "删除顶点"
![adjacency_list_remove_vertex](graph_operations.assets/adjacency_list_remove_vertex.png)
![adjacency_list_remove_vertex](graph_operations.assets/adjacency_list_step5_remove_vertex.png)
以下是邻接表的代码实现。对比上图,实际代码有以下不同。

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

+10 -10
View File
@@ -347,19 +347,19 @@
如下图所示,我们将双向链表的头节点和尾节点视为双向队列的队首和队尾,同时实现在两端添加和删除节点的功能。
=== "LinkedListDeque"
![基于链表实现双向队列的入队出队操作](deque.assets/linkedlist_deque.png)
![基于链表实现双向队列的入队出队操作](deque.assets/linkedlist_deque_step1.png)
=== "push_last()"
![linkedlist_deque_push_last](deque.assets/linkedlist_deque_push_last.png)
![linkedlist_deque_push_last](deque.assets/linkedlist_deque_step2_push_last.png)
=== "push_first()"
![linkedlist_deque_push_first](deque.assets/linkedlist_deque_push_first.png)
![linkedlist_deque_push_first](deque.assets/linkedlist_deque_step3_push_first.png)
=== "pop_last()"
![linkedlist_deque_pop_last](deque.assets/linkedlist_deque_pop_last.png)
![linkedlist_deque_pop_last](deque.assets/linkedlist_deque_step4_pop_last.png)
=== "pop_first()"
![linkedlist_deque_pop_first](deque.assets/linkedlist_deque_pop_first.png)
![linkedlist_deque_pop_first](deque.assets/linkedlist_deque_step5_pop_first.png)
实现代码如下所示:
@@ -372,19 +372,19 @@
如下图所示,与基于数组实现队列类似,我们也可以使用环形数组来实现双向队列。
=== "ArrayDeque"
![基于数组实现双向队列的入队出队操作](deque.assets/array_deque.png)
![基于数组实现双向队列的入队出队操作](deque.assets/array_deque_step1.png)
=== "push_last()"
![array_deque_push_last](deque.assets/array_deque_push_last.png)
![array_deque_push_last](deque.assets/array_deque_step2_push_last.png)
=== "push_first()"
![array_deque_push_first](deque.assets/array_deque_push_first.png)
![array_deque_push_first](deque.assets/array_deque_step3_push_first.png)
=== "pop_last()"
![array_deque_pop_last](deque.assets/array_deque_pop_last.png)
![array_deque_pop_last](deque.assets/array_deque_step4_pop_last.png)
=== "pop_first()"
![array_deque_pop_first](deque.assets/array_deque_pop_first.png)
![array_deque_pop_first](deque.assets/array_deque_step5_pop_first.png)
在队列的实现基础上,仅需增加“队首入队”和“队尾出队”的方法:

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+6 -6
View File
@@ -321,13 +321,13 @@
如下图所示,我们可以将链表的“头节点”和“尾节点”分别视为“队首”和“队尾”,规定队尾仅可添加节点,队首仅可删除节点。
=== "LinkedListQueue"
![基于链表实现队列的入队出队操作](queue.assets/linkedlist_queue.png)
![基于链表实现队列的入队出队操作](queue.assets/linkedlist_queue_step1.png)
=== "push()"
![linkedlist_queue_push](queue.assets/linkedlist_queue_push.png)
![linkedlist_queue_push](queue.assets/linkedlist_queue_step2_push.png)
=== "pop()"
![linkedlist_queue_pop](queue.assets/linkedlist_queue_pop.png)
![linkedlist_queue_pop](queue.assets/linkedlist_queue_step3_pop.png)
以下是用链表实现队列的代码:
@@ -349,13 +349,13 @@
可以看到,入队和出队操作都只需进行一次操作,时间复杂度均为 $O(1)$ 。
=== "ArrayQueue"
![基于数组实现队列的入队出队操作](queue.assets/array_queue.png)
![基于数组实现队列的入队出队操作](queue.assets/array_queue_step1.png)
=== "push()"
![array_queue_push](queue.assets/array_queue_push.png)
![array_queue_push](queue.assets/array_queue_step2_push.png)
=== "pop()"
![array_queue_pop](queue.assets/array_queue_pop.png)
![array_queue_pop](queue.assets/array_queue_step3_pop.png)
你可能会发现一个问题:在不断进行入队和出队的过程中,`front` 和 `rear` 都在向右移动,**当它们到达数组尾部时就无法继续移动了**。为了解决此问题,我们可以将数组视为首尾相接的“环形数组”。

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+6 -6
View File
@@ -319,13 +319,13 @@
如下图所示,对于入栈操作,我们只需将元素插入链表头部,这种节点插入方法被称为“头插法”。而对于出栈操作,只需将头节点从链表中删除即可。
=== "LinkedListStack"
![基于链表实现栈的入栈出栈操作](stack.assets/linkedlist_stack.png)
![基于链表实现栈的入栈出栈操作](stack.assets/linkedlist_stack_step1.png)
=== "push()"
![linkedlist_stack_push](stack.assets/linkedlist_stack_push.png)
![linkedlist_stack_push](stack.assets/linkedlist_stack_step2_push.png)
=== "pop()"
![linkedlist_stack_pop](stack.assets/linkedlist_stack_pop.png)
![linkedlist_stack_pop](stack.assets/linkedlist_stack_step3_pop.png)
以下是基于链表实现栈的示例代码:
@@ -338,13 +338,13 @@
使用数组实现栈时,我们可以将数组的尾部作为栈顶。如下图所示,入栈与出栈操作分别对应在数组尾部添加元素与删除元素,时间复杂度都为 $O(1)$ 。
=== "ArrayStack"
![基于数组实现栈的入栈出栈操作](stack.assets/array_stack.png)
![基于数组实现栈的入栈出栈操作](stack.assets/array_stack_step1.png)
=== "push()"
![array_stack_push](stack.assets/array_stack_push.png)
![array_stack_push](stack.assets/array_stack_step2_push.png)
=== "pop()"
![array_stack_pop](stack.assets/array_stack_pop.png)
![array_stack_pop](stack.assets/array_stack_step3_pop.png)
由于入栈的元素可能会源源不断地增加,因此我们可以使用动态数组,这样就无须自行处理数组扩容问题。以下为示例代码:
Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

+1 -1
View File
@@ -148,7 +148,7 @@ hide:
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
</div>
<p style="margin-top: 2em;">500 幅动画图解、12 种编程语言代码、2000 条社区问答,助你快速入门数据结构与算法</p>
<p style="margin-top: 2em;">500 幅动画图解、12 种编程语言代码、3000 条社区问答,助你快速入门数据结构与算法</p>
</div>
</section>