Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 找到Fermat';使用BFS的三角形中的s点_Algorithm_Graph_Geometry_Breadth First Search - Fatal编程技术网

Algorithm 找到Fermat';使用BFS的三角形中的s点

Algorithm 找到Fermat';使用BFS的三角形中的s点,algorithm,graph,geometry,breadth-first-search,Algorithm,Graph,Geometry,Breadth First Search,给定网格中的3个点,如何找到一个点,使该点与网格中所有3个点的距离之和最小化。这个问题的一个明显答案是费马三角形。我很想知道我们是否可以在图中使用广度优先搜索算法来定位费马点 struct node{ int Person1X,Person1Y,Person2X,Person2Y,Person3X,Person3Y; //X and Y coordinates of all 3 persons int steps; //sum of distances covered by all

给定网格中的3个点,如何找到一个点,使该点与网格中所有3个点的距离之和最小化。这个问题的一个明显答案是费马三角形。我很想知道我们是否可以在图中使用广度优先搜索算法来定位费马点

struct node{
  int Person1X,Person1Y,Person2X,Person2Y,Person3X,Person3Y; //X and Y coordinates of all 3 persons
  int steps;   //sum of distances covered by all 3 person to reach this state
}
在进行BFS时,我们可以设置一个约束, 如果steps>min(三角形任意两条边的总和,以3个人为顶点)返回


不需要搜索

给定“三角形”ABC: 距离总和(p)=距离(A,p)+距离(B,p)+距离(C,p)

其中dist(q,p)=qx px |+| qy py |(曼哈顿距离)

可以看到SumOfDistances(p)=SumOfDistancesx(p)+SumOfDistancesy(p)

因此,您可以独立地通过x轴和y轴上的距离最小化

费马点的x坐标是3个给定x坐标的中值。
费马点的y坐标是3个给定y坐标的中位数。

使用什么距离度量?如果是欧几里德的,请参阅维基百科文章中的方法。如果说曼哈顿,所有三角形的三分之四没有这样的点,那就是曼哈顿。为什么所有三角形的三分之四都没有这样的点呢?我说错了,因为我想到了一个不同的问题。当然,对于网格上的每个三角形ABC,都有一个网格点F,使得AF+BF+CF在曼哈顿距离内最小。但是,对于所有三角形中的3/4,在曼哈顿距离中没有AF=BF=CF的点F:让pqr表示点ABC的平价。(点(x,y)的奇偶性为(x+y)%2。)pqr位于{00000 1010011100101110111}中,并以相同的概率获取每个值。距离偶数奇偶点d的点不可能距离奇数奇偶点d。为了直观地了解为什么这是正确的,请思考当你离开费马点1步时,总距离会发生什么变化。那么,这是否意味着中心点和费马点是相同的?好吧,问题是使用曼哈顿距离,不是通常的欧几里德几何。我认为一个中心意味着你在考虑欧几里德几何。
if(Person1X=Person2X=Person2X)AND(Person1Y=Person2Y=Person3Y) return steps;