Closest Pair Implemetation Python

前端 未结 4 1966
时光说笑
时光说笑 2021-02-04 17:32

I am trying to implement the closest pair problem in Python using divide and conquer, everything seems to work fine except that in some input cases, there is a wrong answer. My

4条回答
  •  隐瞒了意图╮
    2021-02-04 18:10

    You just need to change the seventh line in your closestSplitPair function def from best=(Sy[i],Sy[i+j]) to best=dist(Sy[i],Sy[i+j]) and you will get the correct answer: ((94, 5), (99, -8), 13.92838827718412). You were missing the calling to the dist function.

    This was pointed out by Padraic Cunningham's answer as the first problem.

    Best Regards.

提交回复
热议问题