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