http://poj.org/problem?id=2187
大意:求解点和点之间的最大距离的平方。
记得曾经有一道CF的题自己写了一个3重循环也过了,当时自己怀疑计算机一秒是运算10^9吗,还是数据太弱。。。写了一个1e9的程序,果断超时。看来1e8才是保险值
TLE:
后经分析,此题需要用凸包优化:
我又画个图说明:
我们总能在凸包上寻找另一个点使得凸包上一对点的距离大于图中灰色线段的长。换句话说,题目中要求的距离(的平方)就在凸包上。
(time: 157ms memory: 632k 嘿嘿,效果还行)
后来听说,这题涉及到旋转卡壳和
最远点对。啊,原来还有其他做法。先到这里,继续学习。。。
========================================================================
2016.01.23
学习了旋转卡壳,现在用旋转卡壳来做它:
旋转卡壳用于凸包已经求得基础上寻找一对点的最大距离(当然他还有其他作用)。
凸多边形直径定理:凸多边形P的直径等于P的所有平行支撑线之间距离的最大值。
旋转卡壳的算法展示图片:
(我打不开上面这个链接。。。)
这篇博文的算法实现是比较好的: http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html
相关代码:
ans=max(ans,max(dis(sta[i],sta[q]),dis(sta[i+1],sta[q+1]))); 的解释: 主要考虑到平行线的情况。
POJ 2187 居然用下面那条注释的语句也过了,这应该是数据弱了。。