【暴力】凸包算法

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值