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个顶点,求一个顶点都在凸多边形上,面积最小的三角形,输出三角形面积的二倍

二阶矩阵的行列式(两向量叉积)是求其平行四边形面积,三阶矩阵的行列式即求其平行六面体的体积。另外如果a×b<0,那么ab的逆时针方向(通俗的理解,假设朝上的话,那么a在b的左边),反之亦然。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 2e5+10;
ll a[maxn];
ll n,m;
ll x[maxn],y[maxn];
ll minn = 0x3f3f3f3f3f3f3f3f;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int i;
    ll ans;
    for(i=0; i<n; i++)
    {
        cin>>x[i]>>y[i];
    }
    for(i=0; i<n; i++)
    {
        ll x1 = x[i] - x[(i+1)%n];
        ll y1 = y[i] - y[(i+1)%n];
        ll x2 = x[i] - x[(i+2)%n];
        ll y2 = y[i] - y[(i+2)%n];
        ans = (ll)abs(x1*y2-y1*x2);
        minn = min(ans,minn);
    }
    cout<<minn<<endl;
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值