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.
Examples
Input
4
0 1
3 0
3 3
-1 3
Output
5
Input
3
0 0
1 0
0 1
Output
1
Input
4
-999999991 999999992
-999999993 -999999994
999999995 -999999996
999999997 999999998
Output
3999999948000000156
Note
It is recommended to make all calculations using integer numbers, because floating point precision most likely would not be enough.
题意:有一个由n个点组成的多边形,给出这n个点坐标,求由这n个点其中的三个点为顶点的三角形最小面积。
思路:相邻的三个点组成一个三角形,把每个点为始点,与其后两个点组成的三角形面积求出来,取最小值。(到第n个点时,不要忘记它与第一个点和第二个点组成的三角形)
用叉积(向量)计算三角形面积:
A(x1,y1), B(x2,y2), C(x3,y3),
s=1/2abs(ABAC)
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define N 200010
struct date
{
ll x,y;
}a[N];
ll findx(ll x1,ll y1,ll x2,ll y2)
{
ll ans=abs(x1*y2-y1*x2);
return ans;
}
int main()
{
int i,n;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y;
}
ll mi=4e18+5;//这里mi不要取inf,inf=1061109567,在第三组样例中三角形面积大于inf
a[n+1]=a[1];
a[n+2]=a[2];
for(i=1;i<=n;i++)
{
mi=min(mi,findx(a[i+1].x-a[i].x,a[i+1].y-a[i].y,a[i+2].x-a[i].x,a[i+2].y-a[i].y));
}
cout<<mi<<endl;
return 0;
}
求三角形面积: (要知道三角形坐标)
叉积; (x2-x1)(y3-y1)-(y2-y1)(x3-x1)
坐标顺时针。
海伦公式:area=sqrt(p*(p-a)(p-b)(p-c));
p=(a+b+c)/2;