chore(i8n,learn): processed translations

This commit is contained in:
Crowdin Bot
2021-02-06 04:42:36 +00:00
committed by Mrugesh Mohapatra
parent 15047f2d90
commit e5c44a3ae5
3274 changed files with 172122 additions and 14164 deletions

View File

@ -1,86 +1,96 @@
---
id: 5951a53863c8a34f02bf1bdc
title: 最近对的问题
title: Closest-pair problem
challengeType: 5
videoUrl: ''
forumTopicId: 302232
dashedName: closest-pair-problem
---
# --description--
任务:
Provide a function to find the closest two points among a set of given points in two dimensions, i.e. to solve the [Closest pair of points problem](https://en.wikipedia.org/wiki/Closest pair of points problem "wp: Closest pair of points problem") in the *planar* case.
提供一个函数来在二维中找到一组给定点中最接近的两个点,即求解平面情况下的[最近点对问题](<https://en.wikipedia.org/wiki/Closest pair of points problem> "wp最近点的问题") 。
The straightforward solution is a O(n<sup>2</sup>) algorithm (which we can call *brute-force algorithm*); the pseudo-code (using indexes) could be simply:
直接的解决方案是On <sup>2</sup> )算法(我们可以称之为强力算法);伪代码(使用索引)可以简单地:
<pre><strong>bruteForceClosestPair</strong> of P(1), P(2), ... P(N)
<strong>if</strong> N &#x3C; 2 <strong>then</strong>
<strong>return</strong>
<strong>else</strong>
minDistance ← |P(1) - P(2)|
minPoints ← { P(1), P(2) }
<strong>foreach</strong> i ∈ [1, N-1]
<strong>foreach</strong> j ∈ [i+1, N]
<strong>if</strong> |P(i) - P(j)| &#x3C; minDistance <strong>then</strong>
minDistance ← |P(i) - P(j)|
minPoints ← { P(i), P(j) }
<strong>endif</strong>
<strong>endfor</strong>
<strong>endfor</strong>
<strong>return</strong> minDistance, minPoints
<strong>endif</strong>
</pre>
```
bruteForceClosestPair of P1P2... PN
如果N <2那么
返回∞
其他
minDistance←| P1 - P2|
minPoints←{P1P2}
foreachi∈[1N-1]
foreachj∈[i + 1N]
if | Pi - Pj| <minDistance然后
minDistance←| Pi - Pj|
minPoints←{PiPj}
万一
ENDFOR
ENDFOR
return minDistanceminPoints
万一
```
A better algorithm is based on the recursive divide and conquer approach, as explained also at [Wikipedia's Closest pair of points problem](https://en.wikipedia.org/wiki/Closest pair of points problem#Planar_case "wp: Closest pair of points problem#Planar_case"), which is `O(nlog(n))` a pseudo-code could be:
</pre><p>一个更好的算法是基于递归分而治之的方法,正如<a href='https://en.wikipedia.org/wiki/Closest pair of points problem#Planar_case' title='wp最近点的问题#Planar_case'>维基百科最近的一对点问题</a>所解释的那样即On log n;伪代码可以是: </p><pre>最近的xPyP
其中xP是P1.. PN按x坐标排序
yP是P1.. PN按y坐标排序升序
如果N≤3那么
使用强力算法返回xP的最近点
其他
xL←xP点从1到⌈N/2⌉
xR←xP点从⌈N/2⌉+ 1到N.
xmxP⌈N/2⌉ <sub>x</sub>
基←{P∈YPP <sub>X≤XM}</sub>
yR←{p∈yPp <sub>x</sub> > xm}
dLpairL←nearestPairxLyL
dRpairR←nearestRairxRyR
dminpairMindRpairR
如果dL &#x3C;dR
dminpairMindLpairL
万一
yS←{p∈yP| xm - p <sub>x</sub> | &#x3C;dmin}
nS←yS中的点数
(最近,最近的公里)←(dminpairMin
我从1到nS - 1
ki + 1
而k≤nS和ySk <sub>y</sub> -ySi <sub>y</sub> &#x3C;dmin
if | ySk - ySi| &#x3C;最接近的
(最近,最近的公里)←(| ySk - ySi|{ySkySi}
万一
kk + 1
ENDWHILE
ENDFOR
返回最近,最近的
万一
</pre>参考和进一步阅读: <a href='https://en.wikipedia.org/wiki/Closest pair of points problem' title='wp最近点的问题'>最近的一对点问题</a> <a href='http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html' title='链接http//www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html'>最近的一对(麦吉尔)</a> <a href='http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf' title='链接http//www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf'>最近的一对UCSB</a> <a href='http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf' title='链接http//classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf'>最近的一对WUStL</a> <a href='http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt' title='链接http//www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt'>最近的一对IUPUI</a> <p>对于输入,期望参数是一个对象(点)数组,其中<code>x</code><code>y</code>成员设置为数字。对于输出,返回一个包含键的对象: <code>distance</code><code>pair</code>值对(即两对最近点的对)。 </p>
<pre><strong>closestPair</strong> of (xP, yP)
where xP is P(1) .. P(N) sorted by x coordinate, and
yP is P(1) .. P(N) sorted by y coordinate (ascending order)
<strong>if</strong> N ≤ 3 <strong>then</strong>
<strong>return</strong> closest points of xP using brute-force algorithm
<strong>else</strong>
xL ← points of xP from 1 to ⌈N/2⌉
xR ← points of xP from ⌈N/2⌉+1 to N
xmxP(⌈N/2⌉)<sub>x</sub>
yL ← { p ∈ yP : p<sub>x</sub> ≤ xm }
yR ← { p ∈ yP : p<sub>x</sub> > xm }
(dL, pairL) ← closestPair of (xL, yL)
(dR, pairR) ← closestPair of (xR, yR)
(dmin, pairMin) ← (dR, pairR)
<strong>if</strong> dL &#x3C; dR <strong>then</strong>
(dmin, pairMin) ← (dL, pairL)
<strong>endif</strong>
yS ← { p ∈ yP : |xm - p<sub>x</sub>| &#x3C; dmin }
nS ← number of points in yS
(closest, closestPair) ← (dmin, pairMin)
<strong>for</strong> i <strong>from</strong> 1 <strong>to</strong> nS - 1
ki + 1
<strong>while</strong> k ≤ nS <strong>and</strong> yS(k)<sub>y</sub> - yS(i)<sub>y</sub> &#x3C; dmin
<strong>if</strong> |yS(k) - yS(i)| &#x3C; closest <strong>then</strong>
(closest, closestPair) ← (|yS(k) - yS(i)|, {yS(k), yS(i)})
<strong>endif</strong>
kk + 1
<strong>endwhile</strong>
<strong>endfor</strong>
<strong>return</strong> closest, closestPair
<strong>endif</strong>
</pre>
For the input, expect the argument to be an array of objects (points) with `x` and `y` members set to numbers. For the output, return an object containing the key:value pairs for `distance` and `pair` (the pair of two closest points).
**References and further readings:**
<ul>
<li><a href='https://en.wikipedia.org/wiki/Closest pair of points problem' title='wp: Closest pair of points problem' target='_blank'>Closest pair of points problem</a></li>
<li><a href='https://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html' target='_blank'>Closest Pair (McGill)</a></li>
<li><a href='https://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf' target='_blank'>Closest Pair (UCSB)</a></li>
<li><a href='https://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf' target='_blank'>Closest pair (WUStL)</a></li>
</ul>
# --hints--
`getClosestPair`是一个函数。
`getClosestPair` should be a function.
```js
assert(typeof getClosestPair === 'function');
```
距离应如下。
Distance should be the following.
```js
assert.equal(getClosestPair(points1).distance, answer1.distance);
```
要点应如下。
Points should be the following.
```js
assert.deepEqual(
@ -89,13 +99,13 @@ assert.deepEqual(
);
```
距离应如下。
Distance should be the following.
```js
assert.equal(getClosestPair(points2).distance, answer2.distance);
```
要点应如下。
Points should be the following.
```js
assert.deepEqual(