diff --git a/curriculum/challenges/chinese/10-coding-interview-prep/data-structures/breadth-first-search.md b/curriculum/challenges/chinese/10-coding-interview-prep/data-structures/breadth-first-search.md index 98d6794dd6..60681153f0 100644 --- a/curriculum/challenges/chinese/10-coding-interview-prep/data-structures/breadth-first-search.md +++ b/curriculum/challenges/chinese/10-coding-interview-prep/data-structures/breadth-first-search.md @@ -7,7 +7,7 @@ videoUrl: '' # --description-- -到目前为止,我们已经学会了创建图表表示的不同方法。现在怎么办?一个自然的问题是图中任何两个节点之间的距离是多少?输入图遍历算法 。 遍历算法是遍历或访问图中节点的算法。一种遍历算法是广度优先搜索算法。该算法从一个节点开始,首先访问一个边缘的所有邻居,然后继续访问它们的每个邻居。在视觉上,这就是算法正在做的事情。 要实现此算法,您需要输入图形结构和要启动的节点。首先,您需要了解距起始节点的距离。这个你想要开始你所有的距离最初一些大的数字,如`Infinity` 。这为从起始节点无法访问节点的情况提供了参考。接下来,您将要从开始节点转到其邻居。这些邻居是一个边缘,此时你应该添加一个距离单位到你要跟踪的距离。最后,有助于实现广度优先搜索算法的重要数据结构是队列。这是一个数组,您可以在其中添加元素到一端并从另一端删除元素。这也称为FIFO或先进先出数据结构。 +到目前为止,我们已经学会了创建图表表示的不同方法。现在怎么办?一个自然的问题是图中任何两个节点之间的距离是多少?输入图遍历算法 。 遍历算法是遍历或访问图中节点的算法。一种遍历算法是广度优先搜索算法。该算法从一个节点开始,首先访问一个边缘的所有邻居,然后继续访问它们的每个邻居。在视觉上,这就是算法正在做的事情。 要实现此算法,您需要输入图形结构和要启动的节点。首先,您需要了解距起始节点的距离。这个你想要开始你所有的距离最初一些大的数字,如`Infinity` 。这为从起始节点无法访问节点的情况提供了参考。接下来,您将要从开始节点转到其邻居。这些邻居是一个边缘,此时你应该添加一个距离单位到你要跟踪的距离。最后,有助于实现广度优先搜索算法的重要数据结构是队列。这是一个数组,您可以在其中添加元素到一端并从另一端删除元素。这也称为FIFO或先进先出数据结构。 # --instructions-- diff --git a/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-71-ordered-fractions.md b/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-71-ordered-fractions.md index a577d7253b..0e0ff9f7c9 100644 --- a/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-71-ordered-fractions.md +++ b/curriculum/challenges/chinese/10-coding-interview-prep/project-euler/problem-71-ordered-fractions.md @@ -1,31 +1,31 @@ --- id: 5900f3b31000cf542c50fec6 -title: 'Problem 71: Ordered fractions' +title: '关卡 71:有序分数' challengeType: 5 forumTopicId: 302184 --- # --description-- -Consider the fraction, `n`/`d`, where `n` and `d` are positive integers. If `n`<`d` and HCF(`n`,`d`)=1, it is called a reduced proper fraction. +考虑形如 `n`/`d` 的分数,其中 `n` 和 `d` 均为正整数。如果 `n`<`d`,且最大公约数 HCF(`n`,`d`)=1,则该分数被称为最简真分数。 -If we list the set of reduced proper fractions for `d` ≤ 8 in ascending order of size, we get: +如果我们将 `d` ≤ 8 的最简真分数构成的集合按大小升序列出,将得到:
[ruleset] ::= (([comment] | [rule]) [newline]+)* +[comment] ::= # {[any character]} +[rule] ::= [pattern] [whitespace] -> [whitespace] [.] [replacement] +[whitespace] ::= ([tab] | [space]) [[whitespace]] +每行有一条规则。 -如果有的话**。** (期间)出席之前,那么这是一个终止规则,在这种情况下,解释器必须停止执行。 +如果在 \[replacement] 之前有一个 `.`(句点),那么这就是一个终止规则。在这种情况下,解释器必须停止执行。 -规则集由一系列规则和可选注释组成。 +规则集由一系列规则组成,可能包含一些注释。 规则集 -对条目使用以下测试: +我们会对你提交的代码进行如下测试: -规则集1: +**规则集 1:** -
# This rules file is extracted from Wikipedia: +# 此条规则来自 Wikipedia: #-http://en.wikipedia.org/wiki/Markov_Algorithm
A -> apple B -> bag S -> shop T -> the the shop -> my brother -a never used -> .terminating rule +(终止规则) -> .示例文本:
I bought a B of As from T S.
应该生成输出:
规则集2:
I bought a bag of apples from my brother.
终止规则的测试
-# Slightly modified from the rules on Wikipedia +对于这段文本: + +`I bought a B of As from T S.` + +应该输出: + +`I bought a bag of apples from my brother.` + +**规则集 2:** + +终止规则的测试 + +-It produces the thinned output: +细化后的输出图像为:# 基于 Wikipedia 的规则稍做修改 A -> apple B -> bag S -> .shop T -> the the shop -> my brother -a never used -> .terminating rule +(终止规则) -> .-示例文本:
I bought a B of As from T S.
应该生成:
规则集3:
I bought a bag of apples from T shop.
如果没有转义特殊的正则表达式字符,这将测试正确的替换顺序并可能捕获简单的基于正则表达式的替换例程。
+ +对于这段文本: + +`I bought a B of As from T S.` + +应该输出: + +`I bought a bag of apples from T shop.` + +**规则集 3:** + +这条不仅可以用来测试替换顺序是否正确,还可以测试你的代码中对正则表达式的处理是否完备。如果你的代码没有对正则表达式进行正确的转义处理,那在替换的时候就会出现问题。 +# BNF Syntax testing rules A -> apple WWWW -> with @@ -63,77 +84,124 @@ W -> WW S -> .shop T -> the the shop -> my brother -a never used -> .terminating rule +(终止规则) -> .-示例文本:
I bought a B of As W my Bgage from T S.
应该生成:
规则集4:
I bought a bag of apples with my money from T shop.
这将测试规则扫描的正确顺序,并可能捕获以错误顺序扫描的替换例程。它实现了一般的一元乘法引擎。 (请注意,在此实现中,输入表达式必须放在下划线中。)
##一元乘法引擎,用于测试马尔可夫算法实现 -## Donal Fellows。 -一元加法引擎_ + 1 - > _1 + -1 + 1 - > 11+ -通过将乘法的分裂转换为普通的 -addition1! - >!1 -,! - >!+ -_! - > _ -通过复制左侧,右侧乘以1 * 1 - > x,@ y进行一元乘法 -1x - > xX -X, - > 1,1 -X1 - > 1X -_x - > _X -,x - >,X -y1 - > 1y -y_ - > _ -apply1 @ 1 - > x,@ y的下一阶段 -1 @ _ - > @_ -,@ _ - >!_ -++ - > + -添加终止清除_1 - > 1 -1 + _ - > 1 -_ + _ - > -示例文本:
_1111*11111_
应该生成输出:
规则集5:
11111111111111111111
一台简单的图灵机 ,
实施三态繁忙的海狸 。
磁带由0和1组成,状态为A,B,C和H(对于Halt),并且通过在头部所在的字符之前写入状态字母来指示磁头位置。
必须在输入中给出机器操作的初始磁带的所有部分。
除了证明Markov算法是Turing-complete之外,它还让我抓住了C ++实现中的一个错误,这个错误没有被前四个规则集捕获。
图灵机:三态繁忙的海狸 -状态A,符号0 =>写1,向右移动,新状态BA0 - > 1B -状态A,符号1 =>写1,向左移动,新状态C0A1 - > C01 -1A1 - > C11 -状态B,符号0 =>写1,向左移动,新状态A0B0 - > A01 -1B0 - > A11 -状态B,符号1 =>写1,向右移动,新状态BB1 - > 1B -状态C,符号0 =>写1,向左移动,新状态B0C0 - > B01 + +对于这段文本: + +`I bought a B of As W my Bgage from T S.` + +应该输出: + +`I bought a bag of apples with my money from T shop.` + +**规则集 4:** + +这条是用来测试规则扫描的顺序是否正确,并可能捕获以错误顺序扫描的替换例程。这里我们选取了通用的一元乘法引擎(请注意,在此实现中,输入的表达式必须放在两个下划线之间)。 + ++ +这个规则集应将这段输入: + +`000000A000000` + +转换成: + +`00011H1111000` # --hints-- -`markov`是一个功能。 +`markov` 应是一个函数。 ```js assert(typeof markov === 'function'); ``` -`markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")`应该回复“我从我兄弟那里买了一袋苹果”。 +`markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` 应返回 "I bought a bag of apples from my brother."。 ```js assert.deepEqual(markov(rules[0], tests[0]), outputs[0]); ``` -`markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")`应该回来“我从T商店买了一袋苹果。” +`markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")` 应返回 "I bought a bag of apples from T shop."。 ```js assert.deepEqual(markov(rules[1], tests[1]), outputs[1]); ``` -`markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")`应该返回”我从T商店用我的钱买了一袋苹果。“ +`markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")` 应返回 "I bought a bag of apples with my money from T shop."。 ```js assert.deepEqual(markov(rules[2], tests[2]), outputs[2]); ``` -`markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")`应返回”11111111111111111111“。 +`markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")` 应返回 "11111111111111111111"。 ```js assert.deepEqual(markov(rules[3], tests[3]), outputs[3]); ``` -`markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")`应返回”00011H1111000“。 +`markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")` 应返回 "00011H1111000"。 ```js assert.deepEqual(markov(rules[4], tests[4]), outputs[4]); diff --git a/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.md b/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.md index e9c7cb5a05..bca505e935 100644 --- a/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.md +++ b/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.md @@ -1,13 +1,13 @@ --- id: 594810f028c0303b75339ad7 -title: Zhang-Suen thinning algorithm +title: Zhang-Suen 细化算法 challengeType: 5 forumTopicId: 302347 --- # --description-- -This is an algorithm used to thin a black and white i.e. one bit per pixel images. For example, with an input image of: +这是一个黑白图像(二值图像)的细化算法。 例如,输入图像如下: @@ -31,7 +31,7 @@ This is an algorithm used to thin a black and white i.e. one bit per pixel image ######## ####### ###### ############# ########一元乘法引擎,用于测试马尔可夫算法实现 +### by Donal Fellows +# 一元加法引擎 +_+1 -> _1+ +1+1 -> 11+ +# 将乘法转换为普通加法 +1! -> !1 +,! -> !+ +_! -> _ +# 一元乘法,左侧为被乘数,右侧为乘数 +1*1 -> x,@y +1x -> xX +X, -> 1,1 +X1 -> 1X +_x -> _X +,x -> ,X +y1 -> 1y +y_ -> _ +# 下一阶段 +1@1 -> x,@y +1@_ -> @_ +,@_ -> !_ +++ -> + +# 加法的终止条件 +_1 -> 1 +1+_ -> 1 +_+_ -> ++ +对于这段文本: + +`_1111*11111_` + +应该输出: + +`11111111111111111111` + +**规则集5:** + +一台简单的[图灵机](http://en.wikipedia.org/wiki/Turing_machine)包含三个状态的["忙碌海狸"](http://en.wikipedia.org/wiki/Busy_beaver)。纸带由 0 和 1 组成,状态为 A、B、C 和代表终止(Halt)的 H。通过在字符前写状态字母来的方式来指示读写头的位置。机器运行时需要的初始纸带必须通过输入在一开始全部给出。 + +这一规则集除了可以证明 Markov 算法是图灵完备的,它还帮我找出了使用 C++ 完成此题中的一个错误,而且这个错误没有被前四个规则集抓到。 + +# 图灵机:三个状态的"忙碌海狸" +# 状态 A,符号 0 => 写入 1,向右移动,新状态 B +A0 -> 1B +# 状态 A,符号 1 => 写入 1,向左移动,新状态 C +0A1 -> C01 +1A1 -> C11 +# 状态 B,符号 0 => 写入 1,向左移动,新状态 A +0B0 -> A01 +1B0 -> A11 +# 状态 B,符号 1 => 写入 1,向右移动,新状态 B +B1 - > 1B +# 状态 C,符号 0 => 写入 1,向左移动,新状态 B +0C0 - > B01 1C0 - > B11 -状态C,符号1 =>写1,向左移动,停止0C1 - > H01 +# 状态 C,符号 1 => 写入 1,向左移动,停止 +0C1 - > H01 1C1 - > H11 -这个规则集应该转向
000000A000000
成
+
00011H1111000
@@ -52,9 +52,9 @@ It produces the thinned output:-Algorithm
+算法
-Assume black pixels are one and white pixels zero, and that the input image is a rectangular N by M array of ones and zeroes. The algorithm operates on all black pixels P1 that can have eight neighbours. The neighbours are, in order, arranged as: +假设黑像素点为 1,白像素点为 0;则输入图像可以用一个 N * M 的矩阵(或数组)来表示,其中,矩阵中的元素只能为 0 或 1。这个算法对所有黑像素点 P1 进行操作。每个点 P1 都可以有 8 个相邻的点,分别是:
P9 | P2 | P3 |
P7 | P6 | P5 |