该算法是在gift-warping算法的基础上通过排序来预处理数据然后降低时间复杂度的
#include <iostream>
#include <memory>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#define MAXN 100001
using namespace std;
/* 向量 */
struct Vertex {
double x, y;
Vertex(const double & _x = double(), const double & _y = double()) : x(_x), y(_y) {}
};
/* 点 */
struct Point {
double x, y;
Point(const double & _x = double(), const double & _y = double()) : x(_x), y(_y) {}
} points[MAXN];
/* 计算叉积 */
inline double cross(const Vertex & a, const Vertex & b) {
return a.x * b.y - a.y * b.x;
}
/* 计算叉积<a, b> * <a, c> */
inline double cross(const Point & a, const Point & b, const Point & c) {
Vertex vab = Vertex(b.x - a.x, b.y - a.y);
Vertex vac = Vertex(c.x - a.x, c.y - a.y);
return cross(vab, vac);
}
/* 计算两点间的距离 */
inline double dist(const Point &

本文介绍了如何使用C++实现二维凸包的Graham扫描线算法,该算法基于gift-warping,通过数据排序优化了时间效率。
最低0.47元/天 解锁文章
191

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



