nyoj 253:LK的旅行 【旋转卡壳入门】
2024-10-07 13:19:30
求平面最大点对。
找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板)
#include<bits/stdc++.h> using namespace std; struct point { int x,y; point operator -(const point& rhs)const { point ret; ret.x=x-rhs.x; ret.y=y-rhs.y; return ret; } int operator *(const point& rhs)const//叉乘 { return x*rhs.y-y*rhs.x; } bool operator <(const point& rhs)const { return x<rhs.x||x==rhs.x&&y<rhs.y; } } p[],s[]; int top; bool ok(point A,point B,point C) //判断ABC是否是按逆时针顺序给出 { ; } int dist2(point a,point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } int rotating_calipers() { ; point v; ; ; i < top; i++) { v = s[i]-s[(i+)%top]; )%top]-s[cur])) < ) cur = (cur+)%top; ret = max(ret,max(dist2(s[i],s[cur]),dist2(s[(i+)%top],s[(cur+)%top]))); } return ret; } int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); ; i<n; i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+n); top=; ; i<n; i++) //求下凸包 { && !ok(s[top-],s[top-],p[i])) top--; s[top++]=p[i]; } ; ; i>=; i--) //求上凸包 { && !ok(s[top-],s[top-],p[i])) top--; s[top++]=p[i]; } --top; // 首尾点相同,故舍去 int ans=rotating_calipers(); printf("%d\n",ans); } }
最新文章
- SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏
- POJ 1947 (树形DP+背包)
- PNG文件格式具体解释
- 【二叉树->;链表】二叉树结构转双向线性链表结构(先序遍历)
- Linux学习之(())操作符
- 照着例子学习protobuf-python
- jq实战-表单验证
- GIS制图课程目录(持续整理)
- 对于996.ICU这个热门话题,一个在校学生的思考
- 零基础开发一款微信小程序商城
- php使用protobuf3
- Android:剖析源码,随心所欲控制Toast显示
- eclipse中添加jstl标签支持(引入头)
- Action访问Servlet API的三种方法
- jQuery选择元素的方法大全
- OpenGL纹理
- android 读取本地json文件 解决显示乱码显示
- Hibernate3.3.2_JUnit_BoforeClass不报异常的Bug处理
- Integer IntegerCache源码
- golang实现模拟键盘按键
热门文章
- 牛客提高D2t2 幸运数字考试
- String中的CompareTo
- SPSS输出结果如何在word中设置小数点前面显示加0
- php+form表单的文件上传
- ALDS1_1_3_D Areas on the Cross-Section Diagram 遇见了几个有意思的语法问题
- [LeetCode] 4. Median of Two Sorted Arrays(想法题/求第k小的数)
- 关于static以及final关键字
- jsp(java server page)
- phpcms批量更新内容页只更新一点就返回问题
- ";源文件名长度大于文件系统支持的长度无法删除";的解决方案