SP8725 Closest Point Pair 题解
这道题就是要 $\mathcal{O}(n\log n)$ 的分治方法去求平面间的最近点对,只是要多求一个点对的编号。
往存储点的结构体中加一个 $id$,将 $ans$ 设为全局变量,在统计答案时更新 $a$ 和 $b$ 即可,注意在 $r - l = 1$ 时也要更新。
其他注意:
-
double 容易出现精度误差,建议使用 long long。
-
输出时,$a < b$。
时间复杂度 $\mathcal{O}(n\log n)$。