1. 减去一个常量
2. 减去一个常量因子
3. 减去的规模是可变的

# 分治法例子

## 减去一个常量

### 拓扑排序

#### 两张实现算法

##### Kahn算法
L← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
remove a node n from S
insert n into L
foreach node m with an edge e from n to m do
remove edge e from the graph
if m has no other incoming edges then
insert m into S
if graph has edges then
return error (graph has at least onecycle)
else
return L (a topologically sortedorder)


2->8->0->3->7->1->5->6->9->4->11->10->12

##### 基于DFS的拓扑排序
L ← Empty list that will contain the sorted nodes
S ← Set of all nodes with no outgoing edges
for each node n in S do
visit(n)
function visit(node n)
if n has not been visited yet then
mark n as visited
for each node m with an edge from m to ndo
visit(m)


8->7->2->3->0->6->9->10->11->12->1->5->4

##### 两种实现算法的总结

Kahn算法不需要检测图为DAG，如果图为DAG，那么在出度为0的集合为空之后，图中还存在没有被移除的边，这就说明了图中存在环路。

## 减去一个常量因子

### Russian Peasant Multiplication

#### 原理

n * m = n/2 * m n为偶数
n * m = (n-1)/2 * 2m + m (if n > 1 and m if n = 1) n为奇数