You are given a strictly convex polygon. Find the minimal possible area of non-degenerate triangle whose vertices are the vertices of the polygon.
Input
The first line contains a single integer n (3?≤?n?≤?200000) — the number of polygon vertices.
Each of the next n lines contains two integers xi and yi (?-?109?≤?xi,?yi?≤?109) — the coordinates of polygon vertices.
The polygon is guaranteed to be strictly convex. Vertices are given in the counterclockwise order.
Output
It is known that the area of triangle whose vertices are the integer points on the grid is either integer or half-integer.
Output a single integer — the required area, multiplied by 2.
Sample 1
Inputcopy | Outputcopy |
---|---|
4 0 1 3 0 3 3 -1 3 |
5 |
Sample 2
Inputcopy | Outputcopy |
---|---|
3 0 0 1 0 0 1 |
1 |
Sample 3
Inputcopy | Outputcopy |
---|---|
4 -999999991 999999992 -999999993 -999999994 999999995 -999999996 999999997 999999998 |
3999999948000000156 |
Note
It is recommended to make all calculations using integer numbers, because floating point precision most likely would not be enough.
Sponsor
题意:给你一个凸多边形的所有顶点,让求用这几个顶点所能组成的最小三角形面积*2。
思路解析:求最小三角形,当三个顶点相邻的时候所组成的三角形面积最小,遍历寻找最小的三角行就好,同时求面积时用叉乘积计算(非退化三角形(角度不超过180度),所以向量起点在同一点上)最大值设的大一点,用0x3f3f3f3f过不了。
#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
const int N=2e5+5;
struct node
{long long x,y;
}a[N];
long long S(node a,node b,node c)
{long long x1=a.x;long long y1=a.y;long long x2=b.x;long long y2=b.y;long long x3=c.x;long long y3=c.y;return abs((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1));
}
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%lld %lld",&a[i].x,&a[i].y);}a[n+1]=a[1];a[n+2]=a[2];n+=2; //防止最后一两条边做底边时为最小三角形long long ma=0x3f3f3f3f3f3f3f3f; //足够大,不然过不了for(int i=3;i<=n;i++){ma=min(ma,S(a[i-2],a[i-1],a[i]));}printf("%lld\n",ma);return 0;
}