0%

0%: 从0开始的Hexo流程图探险

15%: Graphviz?Dot?这都是什么🧎‍♀️?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
digraph demo4 {
label=<<B>Graphviz基本组成结构</B>>;

labelloc=t; // 标题位置
bgcolor=white; // 背景透明

node[shape=box]; // 结点形状为方形
//edge[style=bold];

// 独立出现的为结点或属性声明, 中括号前为结点名称
graphviz[label="Graphviz"];

subgraph{
layout[label="Layouts"];
script[label="Script Files"];
api[label="APIs"];
rank=same;
}

graphviz -> layout;
graphviz -> script;
graphviz -> api;

// 设置子图
api ->
subgraph{
layout_etc[label="......"];
}

script ->
subgraph{
element[label="Elements"];
attribute[label="Attributes"];
rank=same;
}

layout ->
subgraph{
layout_dot[label="dot"];
layout_neato[label="neato"];
}

element ->
subgraph{
ele_graph[label="Graph"];
ele_node[label="Node"];
ele_edge[label="Edge"];
}
}
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;
First Term
This is the definition of the first term.
Second Term
: This is one definition of the second term.
This is another definition of the second term.

从零开始的算法历险 – 0x01

1. 从两数之和(2-Sum)开始

1.1 问题描述

给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。

示例:

给定 nums = [2, 7, 11, 15], target = 9

因为 nums[0] + nums[1] = 2 + 7 = 9
所以返回 [0, 1]

1.2 问题分析

1.3 实现代码

twosum.cppview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vector<int> twoSum(vector<int>& numbers,int targets){
map<int,int> mapping;
vector<int> result;
// Map<Value, Index>
for(int i = 0;i < numbers.size();i++){
mapping[numbers[i]] = i;
}

for(int i = 0; i < numbers.size();i++){
int searched = targets - numbers[i];
if(mapping.find(searched) != mapping.end() && i != mapping[searched]){
result.push_back(i+1);
result.push_back(mapping[searched] + 1);
break;
}
}
return result;
}

1. 基本使用实例

1.1 一个C程序的内部调用图

如图1.1.a 所示

demo.dotview raw
1
2
3
4
5
6
7
8
9
10
digraph G {
main -> parse -> execute;
main -> init;
main -> cleanup;
execute -> make_string;
execute -> printf;
init -> make_string;
main -> printf;
execute -> compare;
}

如图1.1.b 所示

demo_enhance.dotview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
digraph G {
size = "4,4";
main [shape=box]; /* this is a comment*/
main -> parse [weight=8];
parse -> execute;
main -> init [style=dotted];
main -> cleanup;
execute -> { make_string; printf };
init -> make_string;
edge [color=red];
main -> printf [style=bold,label="100 times"];
make_string [label="make a\nstring"];
node [shape=box,style=filled,color=".7,.3,1.0"];
execute -> compare;
}

2. 从基本结构开始探险

2.1 Node

如图 2.1.a 所示

1
2
3
4
5

diagraph G {
main [label="我是一个☝️节点,名字叫做main"]
}