BZOJ 3707 圈地

题目大意

给出平面上n个点,求最小面积三角形。

思路

暴力能过。。。
于是我只写了暴力。。。
后来看hzwer学长的博客发现了一个有趣的骗分。
将整个序列分块,块内暴力,这样就避免了太远的点之间的计算。
然后旋转几次坐标轴争取枚举到所有的情况。。

CODE(暴力):

#define _CRT_SECURE_NO_WARNINGS

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define MAX 1010
#define INF 1e20
using namespace std;

struct Point{
    double x, y;

    Point(const double &_, const double &__):x(_), y(__) {}
    Point() {}

    void Read() {
        scanf("%lf%lf", &x, &y);
    }
}point[MAX];

inline double Cross(const Point &p1, const Point &p2)
{
    return p1.x * p2.y - p1.y * p2.x;
}

int points;

inline double Calc(const Point &p1, const Point &p2, const Point &p3)
{
    double re = .0;
    re += Cross(p1, p2);
    re += Cross(p2, p3);
    re += Cross(p3, p1);
    return fabs(re) / 2;
}

int main()
{
    srand(19970806);
    cin >> points; 
    for(int i = 1; i <= points; ++i)
        point[i].Read();
    double ans = INF;
    for(int i = 1; i <= points; ++i)
        for(int j = i + 1; j <= points; ++j)
            for(int k = j + 1; k <= points; ++k)
                ans = min(ans, Calc(point[i], point[j], point[k]));
    cout << fixed << setprecision(2) << ans << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值