题目描述
给定平面上的n个点,找出它们之间最远的点对。
输入格式
多组数据,每组第一行n代表点数,接着n行为点的坐标,坐标为整数,不超过10^18范围。n<=30000。
输出格式
每组一行,最远点对的距离,保留2位小数
样例数据
样例输入
4
0 0
1 1
0 1
1 0
样例输出
1.41
题目分析
最远点对必在凸包上,可用反证法证明。
于是就有O(n^2)算法,枚举凸包上的点统计最远距离。
然而n^2过不了此题,想一想,其实我们做了一些无用功。
对于结点a、b,当a向后移动1位时,b点要得到最优解,只可能不动,或向后移动若干位,所以没有必要每次枚举a重新枚举b,将b旋转着走就行了。
这就是旋转卡壳,均摊时间复杂度位O(n)
源代码
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
inline const