博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ2187:Beauty Contest——题解
阅读量:6894 次
发布时间:2019-06-27

本文共 1304 字,大约阅读时间需要 4 分钟。

题目大意:给n个点,求点对最大距离的平方。

————————————————————

很容易证明最大距离的点对在最大凸包上。

那么就是旋转卡壳的裸题了。

旋转卡壳要不要写讲解呢……

#include
#include
#include
#include
#include
#include
#include
using namespace std;const int N=50001;struct point{ int x; int y;}p[N],q[N];int n,per[N],l;inline point getmag(point a,point b){ point s; s.x=b.x-a.x;s.y=b.y-a.y; return s;}inline int multiX(point a,point b){ return a.x*b.y-b.x*a.y;}inline int dis(point a,point b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}inline bool cmp(int u,int v){ int det=multiX(getmag(p[1],p[u]),getmag(p[1],p[v])); if(det!=0)return det>0; return dis(p[1],p[u])
=2&&multiX(getmag(q[l-1],p[j]),getmag(q[l-1],q[l]))>=0)l--; q[++l]=p[j]; } return;}inline int area(point a,point b,point c){ return multiX(getmag(a,b),getmag(a,c));}int calliper(){ if(l==2)return dis(q[1],q[2]); int res=0; for(int i=1,j=3;i<=l;i++){ while(j%l+1!=i&&area(q[i],q[i%l+1],q[j])<=area(q[i],q[i%l+1],q[j%l+1]))j=j%l+1; res=max(res,dis(q[i],q[j])); res=max(res,dis(q[i%l+1],q[j])); } return res;}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y); graham(); printf("%d\n",calliper()); return 0;}

 

转载于:https://www.cnblogs.com/luyouqi233/p/8094087.html

你可能感兴趣的文章
数据结构--链表
查看>>
设计模式总结
查看>>
为mit scheme添加for循环语句
查看>>
python2.7+webdriver搭建
查看>>
Win10设置vs2010总是以管理员身份运行
查看>>
模块_pip、os模块
查看>>
Python的hasattr() getattr() setattr() 函数使用方法详解
查看>>
flexible.js移动端适配安卓高分辨不兼容问题
查看>>
leetcode — reverse-integer
查看>>
黄浚杰2013551727_构建之法第三次作业
查看>>
java8-lambda表达式
查看>>
js的介绍与主要学习的东西
查看>>
SQL Server进制
查看>>
简单的编辑器
查看>>
Android 数据库管理— — —更新数据
查看>>
cmd命令
查看>>
算法笔记 --- Counting Sort
查看>>
LeetCode 88 Merge Sorted Array
查看>>
HDU 3974 Assign the task
查看>>
如何使cmd窗口正确显示utf-8编码的文字
查看>>