For the two sides attached to the vertex $ A $, $ B $, an area equal to the area of the triangle enclosed by subtracting $ $ AB portion surrounded by a polygonal area. Polygon area enclosed is certain, we hope triangle area as small as possible.
Provided $ C $ to corner vertices, then the $ C $ located at $ AB $ diameter circle, obviously want $ C $ from $ AB $ Recently, when the polygon one edge attached to the wall minimum area of a triangle.
We found $ A $, $ B $ presence monotonic, it can maintain the double pointer, the area of the triangulation maintenance complexity $ O (n) $.
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 4e4 + 5; double sqr(double x) { return x * x; } struct P { double x, y; P() {} P(double _x, double _y) : x(_x), y(_y) {} friend P operator - (const P &a, const P &b) { return P(a.x - b.x, a.y - b.y); } friend double operator * (const P &a, const P &b) { return a.x * b.x + a.y * b.y; } friend double operator ^ (const P &a, const P &b) { return a.x * b.y - a.y * b.x; } } p[maxn]; double dis(P a, P b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); } int n; int dec(int x) { return x - 1; } int inc(int x) { return (x + 1) % n; } double solve() { double ans = 1e18, s = 0; for(int i = 0, j = 1; i < n; ++i) { while((p[inc(j)] - p[j]) * (p[inc(i)] - p[i]) > 0) { s += fabs((p[i] - p[j]) ^ (p[i] - p[inc(j)])); j = inc(j); } double a = fabs((p[i] - p[inc(i)]) ^ (p[i] - p[j])) / dis(p[i], p[inc(i)]); double c = dis(p[i], p[j]); double b = sqrt(sqr(c) - sqr(a)); double area = a * b; ans = min(ans, fabs(fabs(area) - fabs(s))); s -= fabs((p[j] - p[i]) ^ (p[inc(i)] - p[i])); } return ans * 0.5; } int main() { scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%lf%lf", &p[i].x, &p[i].y); double ans = solve(); reverse(p, p + n); printf("%.15f\n", min(ans, solve())); return 0; }