在这里假设可以选择两个相同的点吧……
那么选出来的四个点一定会在凸包上
建立凸包,然后枚举这个四边形的对角线。策略是先枚举对角线上的一个点,然后沿着凸包枚举另一个点。在枚举另一个点的过程中可以使用旋转卡壳找到在对角线两侧、距离对角线最远的两个点,这样的四个点就可以贡献答案。总时间复杂度\(O(n^2)\)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<vector>
#include<cmath>
//This code is written by Itst
using namespace std;
#define ld long double
#define eps 1e-9
#define nxt(x) ((x) % cnt + 1)
bool cmp(ld a , ld b){
return a + eps > b && a - eps < b;
}
struct comp{
ld x , y;
comp(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
comp operator -(comp a){
return comp(x - a.x , y - a.y);
}
bool operator <(const comp a)const{
return x < a.x || cmp(x , a.x) && y < a.y;
}
}now[2010];
int st[2010] , ind[2010];
int top , N , cnt;
inline ld dot(comp a , comp b){
return a.x * b.y - a.y * b.x;
}
inline ld calcS(comp a , comp b , comp c){
return fabs(dot(b - a , c - a)) / 2;
}
void init(){
for(int i = 1 ; i <= N ; ++i){
while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
--top;
st[++top] = i;
}
for(int i = 1 ; i <= top ; ++i)
ind[++cnt] = st[i];
top = 0;
for(int i = N ; i ; --i){
while(top >= 2 && dot(now[i] - now[st[top]] , now[st[top]] - now[st[top - 1]]) > -eps)
--top;
st[++top] = i;
}
for(int i = 2 ; i < top ; ++i)
ind[++cnt] = st[i];
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in","r",stdin);
//freopen("out","w",stdout);
#endif
scanf("%d" , &N);
for(int i = 1 ; i <= N ; ++i)
scanf("%Lf %Lf" , &now[i].x , &now[i].y);
sort(now + 1 , now + N + 1);
init();
if(cnt == 3)
cout << fixed << setprecision(3) << calcS(now[st[1]] , now[st[2]] , now[st[3]]);
else{
ld ans = 0;
for(int i = 1 ; i <= cnt ; ++i){
int p = i , q = nxt(nxt(i));
for(int j = nxt(nxt(i)) ; nxt(j) != i ; j = nxt(j)){
while(calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(p)]] , now[ind[i]] , now[ind[j]]))
p = nxt(p);
while(calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]) < calcS(now[ind[nxt(q)]] , now[ind[i]] , now[ind[j]]))
q = nxt(q);
ans = max(ans , calcS(now[ind[p]] , now[ind[i]] , now[ind[j]]) + calcS(now[ind[q]] , now[ind[i]] , now[ind[j]]));
}
}
cout << fixed << setprecision(3) << ans;
}
return 0;
}