版本比较
二维凸包学习笔记
正文
增加 6 行删除 6 行
34 行未改动35363738394041424326 行未改动70717273747576777879808117 行未改动991001011021031041051061078 行未改动11611711811912012112212312412512623 行未改动34 行未改动```cppbool cmp(Point a, Point b) {double x = (p[1] - a) & (p[1] - b); //叉乘结果if(sign(x) == 1) return 1; //返回旋转方向(sign 是三态函数,表示该数的符号,1->正,-1->负,0->零)else return 0;}```接下来我们考虑如何去除影响凸性的点。26 行未改动using namespace std;const int N = 1e5 + 5;const double eps = 1e-8;int n;struct Point { //向量半家桶double x, y;Point(){ x = 0, y = 0; }Point(double a, double b){ x = a, y = b; }friend Point operator +(Point a, Point b) { return (Point){a.x + b.x, a.y + b.y}; }friend Point operator -(Point a) { return (Point){-a.x, -a.y}; }17 行未改动bool cmp(Point a, Point b) { //极角排序比较函数double x = (p[1] - a) & (p[1] - b);if(sign(x) == 1) return 1;else return 0;}int main() {scanf("%d", &n);8 行未改动while(top > 1 && sign((st[top - 1] - st[top]) & (st[top] - p[i])) <= 0) top--;st[++top] = p[i];}st[++top] = p[1]; //加入开始点连成整个凸包double ans = 0;for(int i = 1; i < top; i++) ans += Distance(st[i], st[i + 1]); //计算周长printf("%.2lf\n", ans);return 0;}```23 行未改动34 行未改动35363738394041424326 行未改动70717273747576777879808117 行未改动991001011021031041051061078 行未改动11611711811912012112212312412512623 行未改动34 行未改动```cppbool cmp(Point a, Point b) {double x = (p[1] - a) & (p[1] - b); //叉乘结果if(sign(x) == 1) return 1; //返回旋转方向(sign 是三态函数,表示该数的符号,1->正,-1->负,0->零)else return 0;}```接下来我们考虑如何去除影响凸性的点。26 行未改动using namespace std;const int N = 1e5 + 5;const double eps = 1e-8;int n;struct Point { //向量半家桶double x, y;Point(){ x = 0, y = 0; }Point(double a, double b){ x = a, y = b; }friend Point operator +(Point a, Point b) { return (Point){a.x + b.x, a.y + b.y}; }friend Point operator -(Point a) { return (Point){-a.x, -a.y}; }17 行未改动bool cmp(Point a, Point b) { //极角排序比较函数double x = (p[1] - a) & (p[1] - b);if(sign(x) == 1) return 1;else return 0;}int main() {scanf("%d", &n);8 行未改动while(top > 1 && sign((st[top - 1] - st[top]) & (st[top] - p[i])) <= 0) top--;st[++top] = p[i];}st[++top] = p[1]; //加入开始点连成整个凸包double ans = 0;for(int i = 1; i < top; i++) ans += Distance(st[i], st[i + 1]); //计算周长printf("%.2lf\n", ans);return 0;}```23 行未改动