暴力过了
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double powdis(point p1,point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(te==&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
double Graham()
{
int pos;
double minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int top=;
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>)top--;
s[++top]=p[i];
}
/* for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
double ans=;
for(int i=;i<top;i++)
{
for(int j=i+;j<top;j++)
{
ans=max(ans,powdis(s[i],s[j]));
}
}
return ans;
}
int main()
{
/* ios::sync_with_stdio(false);
cin.tie(0);*/
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%.0f\n",Graham());
}
return ;
}
暴力枚举
但是旋转卡壳死活过不了,
10
0 0
10000 0
1 100
2 199
9999 100
9998 199
100 -900
200 -1799
9800 -1799
9900 -900
这组数据过不了,
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; struct point{
double x,y;
};
point p[N],s[N];
int n;
double dir(point p1,point p2,point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x);
}
double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double powdis(point p1,point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool comp(point p1,point p2)
{
double te=dir(p[],p1,p2);
if(te<)return ;
if(te==&&dis(p[],p1)<dis(p[],p2))return ;
return ;
}
double Graham()
{
int pos;
double minx,miny;
minx=miny=inf;
for(int i=;i<n;i++)
{
if(p[i].x<minx||(p[i].x==minx&&p[i].y<miny))
{
minx=p[i].x;
miny=p[i].y;
pos=i;
}
}
swap(p[],p[pos]);
sort(p+,p+n,comp);
int top=;
p[n]=p[];
s[]=p[],s[]=p[],s[]=p[];
for(int i=;i<=n;i++)
{
while(top>=&&dir(s[top-],s[top],p[i])>)top--;
s[++top]=p[i];
}
/* for(int i=0;i<top;i++)
cout<<s[i].x<<" "<<s[i].y<<endl;*/
//Rotating Calipers
double ans=;
int resx=,resy=;
for(int i=;i<top;i++)
{
if(s[i].x==s[].x)resx++;
if(s[i].y==s[].y)resy++;
}
if(resx==top||resy==top)return powdis(s[],s[top-]);
if(top==)ans=powdis(s[],s[]);
else
{
int j=;
for(int i=;i<top;i++)
{
while(dir(s[i],s[i+],s[j+])>=dir(s[i],s[i+],s[j]))
j=(j+)%top;
// cout<<endl;
// cout<<i<<" "<<j<<endl;
// cout<<powdis(s[i],s[j])<<" "<<powdis(s[i],s[j+1])<<endl;
ans=max(ans,max(powdis(s[j],s[i]),powdis(s[j+],s[i])));
}
}
return ans;
}
int main()
{
/* ios::sync_with_stdio(false);
cin.tie(0);*/
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
printf("%.0f\n",Graham());
}
return ;
}
/*
4
0 0
0 1
1 1
1 0
*/
rc
不知道哪里出错了,希望有路过的大神帮忙改改错