POJ 2187 求凸包上最长距离
简单的旋转卡壳题目
以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离
这里求的是距离的平方,所有过程都是int即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
#define eps 1e-9
int n , top; int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} struct Point{
int x,y;
Point(int x= , int y=):x(x),y(y){}
bool operator==(const Point &m) const{
return x==m.x&&y==m.y;
}
int squaredDis(){return x*x+y*y;}
void input(){scanf("%d%d" , &x , &y);}
void print(){cout<<x<<" "<<y<<endl;}
}po[N] , rec[N] , p;
typedef Point Vector; Vector operator+(Vector a , Vector b){return Vector(a.x+b.x , a.y+b.y);}
Vector operator-(Vector a , Vector b){return Vector(a.x-b.x , a.y-b.y);}
Vector operator*(Vector a , double b){return Vector(a.x*b , a.y*b);}
Vector operator/(Vector a , double b){return Vector(a.x/b , a.y/b);} int Cross(Vector a , Vector b){return a.x*b.y-b.x*a.y;}
double Len(Vector a){return sqrt(a.x*a.x*1.0+a.y*a.y);} bool cmp(Point a , Point b){
int v = Cross(a , b);
if(v == ) return a.x<b.x;
else return v>;
} void Graham(Point *a , Point *rec)
{
sort(a , a+n , cmp);
// for(int i=0 ; i<n ; i++) cout<<i<<" "<<a[i].x<< " "<<a[i].y<<endl;
rec[] = a[] , rec[] = a[];
top=;
for(int i= ; i<n ; i++){
while(top> && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top] = a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
int tmp = top;
for(int i=n- ; i>= ; i--){
while(top>tmp && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top]=a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
} int maxDis(Point *a)
{
int la=top- , p= , q=;
int maxn = ;
for(p= ; p<top ; p++){
while(Cross(a[p]-a[la] , a[q+]-a[la]) - Cross(a[p]-a[la] , a[q]-a[la])>)
q=(q+)%top;
maxn = max(maxn , (a[q]-a[la]).squaredDis());
maxn = max(maxn , (a[q]-a[p]).squaredDis());
la = p;
}
return maxn;
} int main()
{
// freopen("a.in" , "r" , stdin);
while(~scanf("%d" , &n))
{
for(int i= ; i<n ; i++) po[i].input();
p = po[];
for(int i= ;i<n ; i++)
if(po[i].y<p.y||(po[i].y==p.y&&po[i].x<p.x)) p=po[i];
Graham(po , rec);
int ans = maxDis(rec);
cout<<ans<<endl;
}
return ;
}
POJ 2187 求凸包上最长距离的更多相关文章
- poj 3525 求凸包的最大内切圆
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3640 ...
- POJ 1118 求平面上最多x点共线
题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...
- POJ 2187 /// 凸包入门 旋转卡壳
题目大意: 求最远点对距离 求凸包上的最远点对 挑战263页 #include <cstdio> #include <string.h> #include <algori ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
随机推荐
- Android网络编程系列 一 TCP/IP协议族之传输层
这篇借鉴的文章主要是用于后续文章知识点的扩散,在此特作备份和扩散学习交流. 传输层中有TCP协议与UDP协议. 1.UDP介绍 UDP是传输层协议,和TCP协议处于一个分层中,但是与TCP协议不同,U ...
- samtools常用命令详解(转)
转自:samtools常用命令详解 samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和ba ...
- mouseover,mouseenter,mouseleave,mouseout
mouseover和mouseout对应 //鼠标移入移出触发该元素及子元素 mouseenter和mouseleave对应 //鼠标移入移出只触发该元素 看完例子即可知道其区别: mouseover ...
- HTML5自学笔记[ 5 ]JSON的新方法
eval和JSON.parse的区别:eval:可以解析任何字符串为js:parse:只能解析JSON形式的字符串变为js(更安全). json格式的字符串中的属性名必须加双引号“”. stringi ...
- Shell基础:常用技巧&重定向&管道操作
Shell脚本介绍和常用工具 Shell脚本 Shell脚本:实际就是windows里的批处理脚本,多条可一次执行的Shell命令集合.Linux上的脚本可以用很多种语言实现,bash shell是比 ...
- Linux服务器下用svn创建多个项目
(1): 创建svn仓库路径 mkdir -p /opt/svn/project1 mkdir -p /opt/svn/project2 svnadm ...
- md5算法原理一窥(其一)
首先,需要了解的事,md5并不是传说中的加密算法,只是一种散列算法.其加密的算法并不是我们说所的那样固定不变,只是一种映射的关系. 所以解密MD5没有现成的算法,只能用穷举法,把可能出现的明文,用MD ...
- mysql关于编码部分(乱码出现的原因和解决方法)
在使用mysql客户端时,我们会经常出现一个这样一个问题,就是原先好好文字,怎么输入之后就出现乱码了呢? 出现这样的问题: 第一个原因: 可能是这是我们新安装的一个mysql,没有经过配置,第二个原因 ...
- python中数据的变量和字符串的常用使用方法
1.查看变量类型: a=2 print(a,type(a)) print的用法:在print后面跟多个输出,可以用逗号分隔. 回收变量名,如把a存储不同的数据,你不需要删除原有变量就可以直接赋值 2. ...
- SpringMvc之handler深入AbstractControllerhe和MultiActionController和内部资源视图解析器
AbstractControllerhe 若处理器继承自AbstractController类,那么该控制器就具有了一些新功能.因为AbstractController类还继承自一个父类WebCont ...