旋转卡壳——模板(对踵点)

news/2024/7/1 9:13:58

这东西学了我大概两天吧。。其实不应该学这么久的,但是这两天有点小困,然后学习时间被削了很多\(QwQ\)

说几个坑点。

- 对于题目不保证有凸包的情况,要选用左下角的点,而非单纯的最下边的点构造凸包。

- 对于凸包中只有\(1/2\)个点的情况,要注意特殊判断。

算法流程就比较简单了。先构造一个凸包,然后利用对踵点都是逆时针跑(类似于两把尺子卡着凸包转)的原理,每次判断到当前直线距离最远的点,更新当前对踵点即可。

例题 【luogu P1452】Beauty contest

#include <bits/stdc++.h>
#define N 50010
using namespace std;struct point {int x, y;
}arr[N], hull[N];int n, top;int cross (point u1, point u2, point v1, point v2) {return (u2.x - u1.x) * (v2.y - v1.y) - (u2.y - u1.y) * (v2.x - v1.x);
}int point_dis (point u, point v) {return (v.x - u.x) * (v.x - u.x) + (v.y - u.y) * (v.y - u.y);
}bool cmp (point lhs, point rhs) {if (cross (arr[1], lhs, arr[1], rhs) < 0) return false;if (cross (arr[1], lhs, arr[1], rhs) > 0) return true;return point_dis (arr[1], lhs) < point_dis (arr[1], rhs);
}void get_hull () {sort (arr + 2, arr + 1 + n, cmp);hull[++top] = arr[1];for (int i = 2; i <= n; ++i) {while (top > 1 && cross (hull[top - 1], hull[top], hull[top], arr[i]) <= 0) --top;hull[++top] = arr[i];}hull[top + 1] = arr[1];
}int get_ans () {if (top == 1) return 0;if (top == 2) return point_dis (hull[1], hull[2]);int v = 2, ans = 0;for (int u = 1; u <= top; ++u) {while (cross (hull[u], hull[u + 1], hull[u + 1], hull[v]) <=cross (hull[u], hull[u + 1], hull[u + 1], hull[v + 1])) {v = v == top ? 1 : v + 1;}ans = max (ans, max (point_dis (hull[u], hull[v]), point_dis (hull[u + 1], hull[v])));}return ans;
}int main () {cin >> n;for (int i = 1; i <= n; ++i) {cin >> arr[i].x >> arr[i].y;if (arr[i].y < arr[1].y || (arr[i].y == arr[1].y && arr[i].x < arr[1].x)) {swap (arr[i], arr[1]);}}get_hull ();cout << get_ans () << endl;
}

转载于:https://www.cnblogs.com/maomao9173/p/10395499.html


http://lihuaxi.xjx100.cn/news/236201.html

相关文章

计算机一级ps2019,2019年计算机一级考试PS基础学习点子:PS菜单中英文对照表.docx...

2019 年计算机一级考试 PS 基础学习点子&#xff1a; PS 菜单中英文对照表PS菜单中英文对照表一、FileNew2.Open3.Open As4.Open RecentClose6.Save7.Save As8.Save for Web9.Revert10.Place11.ImportPDF ImageAnnotationsExportManage WorkflowCheck InUndo Check OutUpload T…

POJ 1236 Network of Schools(tarjan)

Network of SchoolsDescription A number of schools are connected to a computer network. Agreements have been developed among those schools: each school maintains a list of schools to which it distributes software (the “receiving schools”). Note that if B …

trash-cli设置Linux 回收站

trash-cli 设置 Linux 回收站 trash-cli是一个使用 python 开发的软件包&#xff0c;包含 trash-put、restore-trash、trash-list、trash-empty、trash-rm等命令&#xff0c;我们可以通过这条命令&#xff0c;将文件移动到回收站&#xff0c;或者还原删除了的文件。 trash-cli的…

nginx安全日志分析脚本的编写

https://blog.csdn.net/nextdoor6/article/details/51914966

计算机操作培训主持词,魅力女性沙龙会主持词文稿.docx

魅力女性沙龙会主持词??性的学科、一项重要的经济管理工作&#xff0c;是加强经济管理&#xff0c;提高经济效益的重要手段&#xff0c; 经济管理离不开会计&#xff0c; 经济越发展会计工作就显得越重要。会计工作在提高经济在企业的经营管理中起着重要的作用&#xff0c;其…

封装 vue 组件的过程记录

在我们使用vue的开发过程中总会遇到这样的场景&#xff0c;封装自己的业务组件。 封装页面组件前要考虑几个问题&#xff1a;1、该业务组件的使用场景 2、在什么条件下展示一些什么数据&#xff0c;数据类型是什么样的&#xff0c;及长度颜色等 3、如果是通用的内容&#xff0c…

只需3分钟,就能轻松创建 一个SpreadJS的React项目

概述SpreadJS 纯前端表格控件 V11.2(SP2) 已经全面支持了 React 的拓展。接下来我们看下如何利用3分钟快速创建一个 SpreadJS 的 React 项目。1.新建React 项目&#xff08;耗时 1 Min&#xff09;直接运行&#xff1a;npx create-react-app react-spread-sheets还不清楚什么是…

streptavidin-PEG-TRITC 链霉亲和素-聚乙二醇-四甲基罗丹明

产品名称&#xff1a;链霉亲和素-聚乙二醇-四甲基罗丹明 英文名称&#xff1a;streptavidin-PEG-TRITC 纯度&#xff1a;95% 存储条件&#xff1a;-20C&#xff0c;避光&#xff0c;避湿 外观:固体或粘性液体&#xff0c;取决于分子量 PEG分子量可选&#xff1a;350、550、750、…