here
要在n个点中选中4个点求一个矩形的最大面积。
如果枚举点的话复杂度实在太高了,想法就是枚举边,一个矩形的对角线的边的中点是相等的,而且他们的长度也必定相等。
边的数量最多是n*n还是可以接受的
我们计算出来所有的边,然后首先根据距离排序然后根据中间点的位置排序,最后计算面积的时候要用叉积计算防止爆long long的情况发生。
kuangbin的板子还是看着不太习惯,这几天适应一下吧!下边是我自己写的不是他的板子。
ac code
//god with me
#include <bits/stdc++.h>
#define sc(x) cerr << #x << ": " << x << '\n'
#define fg cerr << "----------------------" << el
#define el '\n'
#define hh putchar('\n')
#define pb push_back
#define db double
#define ld long double
#define ll long long
#define int long long
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
const double pi = acos(-1.0);
const int maxp = 1010;
const int N=1505;
struct point
{
int x,y;
point(){}
point (int _x,int _y)
{
x=_x;
y=_y;
}
ll operator ^(const point &a) const
{
return x*a.y-a.x*y;
}
point operator +(const point &a)const
{
return point(x+a.x,y+a.y);
}
point operator-(const point &a)const
{
return point(x-a.x,y-a.y);
}
bool operator<(const point &a)const
{
if(x!=a.x)return x<a.x;
else return y<a.y;
}
bool operator==(const point &a)const
{
return x==a.x&&y==a.y;
}
}P[N];
struct line
{
point mid;
point v;
ll d;
}L[N*N];
bool comp(line a,line b)
{
return a.d==b.d?a.mid.x==b.mid.x?a.mid.y<b.mid.y:a.mid.x<b.mid.x:a.d>b.d;
}
ll sq(int x)
{
return x*x;
}
ll dis(int a,int b)
{
return sq(P[a].x-P[b].x)+sq(P[a].y-P[b].y);
}
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int x,y;
cin>>x>>y;
P[i]={x,y};
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
L[++cnt]={P[i]+P[j],P[i]-P[j],dis(i,j)};
}
}
sort(L+1,L+cnt+1,comp);
ll ans=0;
for(int i=1,j=1;i<=cnt;i=j)
{
while(L[i].d==L[j].d&&L[i].mid==L[j].mid)j++;
for(int k=i;k<j;++k)
{
for(int t=k+1;t<j;++t)
ans=max(ans,abs(L[k].v^L[t].v)>>1);
}
}
cout<<ans<<endl;
}
signed main()
{
int T=1;
for(int i=1;i<=T;i++)
{
solve();
}
return 0;
}