gym224647B

gym224647B

题意:

在二维平面中·选出一个面积最小的三角形,输出这个三角形面积的两倍。

解法:

首先,最优解一定在相邻最近的三个点中产生。
然后我们就可以用向量求三角形的面积。

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define LL long long
const int N = 4e5 + 10;
const LL MAX = 9223372036854775805;

struct Vec { 
    LL x , y; 
} p[N];

inline LL labs(LL x) { 
    return x < 0 ? - x : x ; 
}
inline LL calc(Vec a , Vec b) { 
    return labs (a.x * b.y - a.y * b.x); 
}
LL ans = MAX,n;

int main () {
    scanf("%lld",&n); 
    for(int i = 1 ; i <= n ; i++) {
        scanf("%lld%lld",&p[i].x,&p[i].y);
        p[i + n] = p[i];
    }
    for(int i = 1 ; i <= n ; i++) {
        int j = i + 1,k = j + 1 ; // i - j , k - j 
        Vec a,b;
        a.x = p[i].x - p[j].x; 
        a.y = p[i].y - p[j].y;
        b.x = p[k].x - p[j].x; 
        b.y = p[k].y - p[j].y;
        LL res = calc(a,b) ;
        if(res != 0) ans = min(ans,res);
    }
    printf("%lld\n",ans); 
    //system("pause");
    return 0 ;
}

转载于:https://www.cnblogs.com/Repulser/p/11455748.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值