1. 前言
基本上就是最原始的暴力,多余的计算很多。试过优化,但是弄出了一堆bug,找的焦头烂额。最终放弃了,反正就是手痒实现着玩的,能AC就先算了。
算法本身很简单,主要是特殊情况的处理有点烦,debug的时候实在有点暴躁。
HDUOJ
2. 实现
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<double, double> Point_t;
typedef vector<Point_t> PointVec_t;
typedef set<Point_t> PointSet_t;
int checkPoint(const Point_t &p1, const Point_t &p2, const Point_t &p3)
{
double result = p1.first * p2.second + p3.first * p1.second
+ p2.first * p3.second - p3.first * p2.second
- p2.first * p1.second - p1.first * p3.second
;
if (fabs(result) < 1e-3)
{
return 0;
}
else if (result > 0.0)
{
return 1;
}
else
{
return -1;
}
}
int cmpXrange(const Point_t& p0, const Point_t& p1)
{
if (p0.first < p1.first)
{
return 1;
}
else
{
return -1;
}
}
bool cmpByX(const Point_t& p0, const Point_t& p1)
{
return p0.first < p1.first;
}
double myDistance(const Point_t &p0, const Point_t &p1)
{
return sqrt(((p1.first - p0.first) * (p1.first - p0.first)) +
((p1.second - p0.second) * (p1.second - p0.second)));
}
void bruteConvexHull(const PointVec_t &inPointVec, PointSet_t &outPointSet)
{
bool isFirstCheck = true;
int checkResult, firstResult;
for (int i = 0; i < inPointVec.size(); ++i)
{
for (int j = i + 1; j < inPointVec.size

这篇博客介绍了暴力求解凸包算法的过程,强调了特殊情况处理,如三点共线和重复点问题。作者在处理三点共线时,区分了不同情况,并提供了判定代码。对于重复点,建议输入去重,但指出单点重复情况仍需考虑。在优化过程中遇到的坑,如重复计算导致的问题,由于优化尝试失败,最终恢复了原始实现。
最低0.47元/天 解锁文章
3392

被折叠的 条评论
为什么被折叠?



