0.50
27.00
#include<bits/stdc++.h>//(求凸包最大内接三角形)O(n^2) #define ll long long #define N 50003 using namespace std; const double pi = acos(-1.0); struct node { double x, y; node(double X = 0, double Y = 0) { x = X, y = Y; } } a[N], ch[N]; node operator-(node a, node b) { return node(a.x - b.x, a.y - b.y); } node operator+(node a, node b) { return node(a.x + b.x, a.y + b.y); } node operator*(node a, double t) { return node(a.x * t, a.y * t); } bool operator<(node a, node b) { return a.x < b.x || a.x == b.x && a.y < b.y; } int n, m; double cross(node a, node b) { return a.x * b.y - a.y * b.x; } void convexhull() { sort(a + 1, a + n + 1); m = 0; if (n == 1) { ch[++m] = a[1]; return; } for (int i = 1; i <= n; i++) { while (m > 1 && cross(ch[m - 1] - ch[m - 2], a[i] - ch[m - 2]) <= 0) m--; ch[m++] = a[i]; } int k = m; for (int i = n - 1; i >= 1; i--) { while (m > k && cross(ch[m - 1] - ch[m - 2], a[i] - ch[m - 2]) <= 0) m--; ch[m++] = a[i]; } m--; } double rotating() { if (m <= 2) return 0; if (m == 3) return fabs(cross(ch[1] - ch[0], ch[2] - ch[0])) / 2; double ans = 0; for (int i = 0; i < m; i++) { int j = (i + 1) % m; int k = (j + 1) % m; while (fabs(cross(ch[i] - ch[j], ch[i] - ch[k])) < fabs(cross(ch[i] - ch[j], ch[i] - ch[(k + 1) % m]))) k = (k + 1) % m; while (i != j && k != i) { ans = max(ans, fabs(cross(ch[i] - ch[j], ch[i] - ch[k]))); while (fabs(cross(ch[i] - ch[j], ch[i] - ch[k])) < fabs(cross(ch[i] - ch[j], ch[i] - ch[(k + 1) % m]))) k = (k + 1) % m; j = (j + 1) % m; } } return ans / 2.0; } int main() { ios::sync_with_stdio(false); cin.tie(0); while (cin >> n && n != -1) { for (int i = 1; i <= n; i++)cin >> a[i].x >> a[i].y; convexhull(); double ans = rotating(); cout << fixed << setprecision(2) << ans << endl; } return 0; }
原文:https://www.cnblogs.com/nublity/p/11755395.html