c++ 二维凸包 Graham 扫描线算法模板

本文介绍了如何使用C++实现二维凸包的Graham扫描线算法,该算法基于gift-warping,通过数据排序优化了时间效率。
摘要由CSDN通过智能技术生成

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值