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.

Sample 1

InputcopyOutputcopy
4
0 1
3 0
3 3
-1 3
5

Sample 2

InputcopyOutputcopy
3
0 0
1 0
0 1
1

Sample 3

InputcopyOutputcopy
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Monster_six

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值