题目大意
给出平面上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;
}