思路:

求个凸包

旋转卡壳一下

就求出来最远点对了

注意共线情况

也就是说   凸包如果有一堆点共线保留端点即可

//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=;
int n,k,top,now=,ans;
struct P{int x,y;P(){}P(int X,int Y){x=X,y=Y;}}p[N],tb[N];
bool cmp(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int operator*(P a,P b){return a.x*b.y-a.y*b.x;}
P operator-(P a,P b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b,P c){return (a-c)*(b-c);}
int dis(P a){return a.x*a.x+a.y*a.y;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
sort(p+,p++n,cmp);
for(int i=;i<=n;i++){
while(top>&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}k=top;
for(int i=n-;i;i--){
while(top>k&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}
for(int i=;i<top;i++){
while((tb[i+]-tb[i])*(tb[now]-tb[i])<(tb[i+]-tb[i])*(tb[now+]-tb[i])){
now++;if(now==top)now=;
}ans=max(ans,dis(tb[i]-tb[now]));
}printf("%d\n",ans);
}

POJ 2187 凸包+旋转卡壳的更多相关文章

  1. poj 2187【旋转卡壳模板】

    求平面最远点对 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath& ...

  2. poj 2187 Beauty Contest(二维凸包旋转卡壳)

    D - Beauty Contest Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. poj 2079 Triangle (二维凸包旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u Submit Stat ...

  4. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  5. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  6. Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)

    题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...

  7. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  8. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

  9. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

随机推荐

  1. noip模拟赛 入阵曲

    分析:其实很容易想到O(n^3m^3)的算法,枚举x1,x2,y1,y2,再统计一下和.求和可以用前缀和,能优化到O(n^2m^2),能得到60分.对于特殊性质的点,求一下a[i][j]与k的最小公倍 ...

  2. poj 3648 2-sat 输出任意一组解模板

    转载地址:http://blog.csdn.net/qq172108805/article/details/7603351 /* 2-sat问题,题意:有对情侣结婚,请来n-1对夫妇,算上他们自己共n ...

  3. [bzoj4826][Hnoi2017]影魔_单调栈_主席树

    影魔 bzoj-4826 Hnoi-2017 题目大意:给定一个$n$个数的序列$a$,求满足一下情况的点对个数: 注释:$1\le n,m\le 2\cdot 10^5$,$1\le p1,p2\l ...

  4. Memcached集群之通过Repcached实现主从复制(待实践)

    暂时了解有这东西,不搭建了. Mamcached可以通过Repcached实现主从复制.有以下优缺点: 优点: 1.能够实现Cache的冗余功能 2.主从之间可以互相读写(亮点) 参考: http:/ ...

  5. Nginx教程收集

    学习要系统,最推荐的方式是看书. 下面是收集的一些Nginx教程: https://www.gitbook.com/book/yinsigan/nginx/details http://www.ngi ...

  6. scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld

    scala 入门Eclipse环境搭建及第一个入门经典程序HelloWorld 学习了: http://blog.csdn.net/wangmuming/article/details/3407911 ...

  7. C#中Stack&lt;T&gt;类的使用及部分成员函数的源代码分析

    Stack<T>类 Stack<T> 作为数组来实现. Stack<T> 的容量是 Stack<T> 能够包括的元素数. 当向 Stack<T&g ...

  8. chorme requestBody

    https://stackoverflow.com/questions/18534771/chrome-extension-how-to-get-http-response-body Chrome w ...

  9. iOS开发——基础篇——assign,copy,retain之间的区别以及weak和strong的区别

    @property (nonatomic, assign) NSString *title; 什么是assign,copy,retain之间的区别? assign: 简单赋值,不更改索引计数(Refe ...

  10. beego4---web项目结构

    app.conf appname = blog1 httpport = runmode = dev controllersmy package controllersmy //跟外面的包名一致 imp ...