Sol
简单计算几何。
直接把四边形拆成两个三角形,枚举两侧最大的即可。
注意凹多边形,如果所有的点都在同侧,那么需要最大的减去最小的才行。
Code
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define pf push_front
#define desktop "C:\\Users\\incra\\Desktop\\"
#define IOS ios :: sync_with_stdio (false),cin.tie (0),cout.tie (0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> PII;
const int dx[] = {1,0,-1,0},dy[] = {0,-1,0,1};
template <typename T1,typename T2> bool tomax (T1 &x,T2 y) {if (y > x) return x = y,true;return false;
}
template <typename T1,typename T2> bool tomin (T1 &x,T2 y) {if (y < x) return x = y,true;return false;
}
LL power (LL a,LL b,LL p) {LL ans = 1;while (b) {if (b & 1) ans = ans * a % p;a = a * a % p;b >>= 1;}return ans;
}
int fastio = (IOS,0);
#define endl '\n'
#define puts(s) cout << (s) << endl
typedef pair <double,double> PDD;
const int N = 310;
int n;
PDD a[N];
PDD operator - (PDD a,PDD b) {return {a.x - b.x,a.y - b.y};
}
double cross (PDD i,PDD j) {return i.x * j.y - i.y * j.x;
}
void mian () {cin >> n;for (int i = 1;i <= n;i++) cin >> a[i].x >> a[i].y;double ans = 0;for (int i = 1;i <= n;i++) {for (int j = i + 1;j <= n;j++) {double mx1 = 0,mx2 = 1e18,mx3 = 0,mx4 = 1e18;int c1 = 0,c2 = 0;for (int k = 1;k <= n;k++) {if (k == i || k == j) continue;double s = cross (a[j] - a[i],a[k] - a[i]);if (s < 0) tomax (mx1,-s),tomin (mx2,-s),c1++;else tomax (mx3,s),tomin (mx4,s),c2++;}if (c1 && c2) tomax (ans,mx1 + mx3);if (c1 >= 2) tomax (ans,mx1 - mx2);if (c2 >= 2) tomax (ans,mx3 - mx4);}}cout << fixed << setprecision (10) << ans / 2 << endl;
}
int main () {int T = 1;// cin >> T;while (T--) mian ();return 0;
}