B - Minimal Area Gym - 101755B

添加链接描述

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值