码迷,mamicode.com
首页 > 其他好文 > 详细

gym224647B

时间:2019-09-03 22:09:08      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:system   sys   algo   include   产生   lld   print   amp   平面   

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

gym224647B

标签:system   sys   algo   include   产生   lld   print   amp   平面   

原文地址:https://www.cnblogs.com/Repulser/p/11455748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!