anayisis
这是一道毒瘤题
留坑待补~~(赶作业去了)~~
code
#include<bits/stdc++.h>
#define EPS 1e-8
#define convex Conv
using namespace std;
template<typename T>void read(T &x){
x=0;char r=getchar();T neg=1;
while(r>'9'||r<'0'){if(r=='-')neg=-1;r=getchar();}
while(r>='0'&&r<='9'){x=(x<<3)+(x<<1)+r-'0';r=getchar();}
x*=neg;
}
double max(double a, double b)
{
return a > b ? a : b;
}
struct node{
double x;double y;
node():x(0),y(0){}
node(double x,double y):x(x),y(y){}
};
/*inline bool cmp(node a,node b){
if(a.x==b.x)return a.y<b.y;//
return a.x<b.x;
}*/
bool cmp(const node p1, const node p2)//比较函数,不用极角,用坐标(x, y);
{
return ((p1.y == p2.y && p1.x < p2.x) || p1.y < p2.y);//找最左下角的点为最小点
}
inline node vec(node start,node end){
return node(end.x-start.x,end.y-start.y);
}
inline double cro(node x1,node x2){
return (x1.x*x2.y-x2.y*x1.x);
}
inline double dis(node a,node b){
return ((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
int sgn(double x)
{
if (fabs(x) < EPS)
return 0;
return x < 0 ? -1 : 1;
}
double x_multi(node p1, node p2, node p3)
{
return ((p3.x - p1.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p3.y - p1.y));
}
int n;//
int len;
const int maxn=50000+10;
node p[maxn];
node Conv[maxn];
inline void Andrew(){
int top=1;
Conv[0]=p[0];
Conv[1]=p[1];
for(int i=2;i<n;++i){
while(top>0&&sgn(x_multi(Conv[top - 1], Conv[top], p[i])) <= 0){//sgn(cro(vec(Conv[top-1],Conv[top]),vec(Conv[top],p[i])))<=0){
--top;
}
Conv[++top]=p[i];
}
int tmp=top;
for(int i=n-2;i>=0;--i){
while(top>tmp&&sgn(x_multi(Conv[top - 1], Conv[top], p[i])) <= 0){//sgn(cro(vec(Conv[top-1],Conv[top]),vec(Conv[top],p[i])))<=0){
--top;
}
Conv[++top]=p[i];
}
//for(int i=0;i<=top;i++)printf("%.0f, %.0f\n",Conv[i].x,Conv[i].y);
len=top;
}
inline void rotating_calipers(){
double ans=0;
int _p=1;
//int q=1;
Conv[n]=Conv[0];
for(int i=0;i<=len;++i){
while (x_multi(convex[i],convex[i+1],convex[_p+1])>x_multi(convex[i],convex[i+1],convex[_p]))//while(cro(vec(p[i],p[i+1]),vec(p[i],p[_p]))<cro(vec(p[i],p[i+1]),vec(p[i],p[_p+1]))){
_p=(_p+1)%len;
ans=max(ans,(max(dis(convex[_p],convex[i]),dis(convex[_p+1],convex[i+1]))));
}/*for (int p = 0; p < n; p++)
{
while (x_multi(convex[p], convex[p + 1], convex[q + 1]) > x_multi(convex[p], convex[p + 1], convex[q]))
q = (q + 1) % n;
ans = max(ans, max(dis(convex[p], convex[q]), dis(convex[p + 1], convex[q + 1])));//ans为距离的平方
}*/
printf("%.0lf\n",ans);
}
int main(){
//freopen("datain2.txt","r",stdin);
read(n);
for(int i=0;i<n;++i){scanf("%lf%lf",&p[i].x,&p[i].y);}
sort(p,p+n,cmp);
Andrew();
rotating_calipers();
return 0;
}