旋转卡壳

Sample Input

4
0 0
0 1
1 1
1 0
Sample Output

2

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; struct Point
{
int x,y;
Point(int _x = ,int _y = )
{
x = _x; y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
int operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
int operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%d%d",&x,&y);
}
};
//距离的平方
int dist2(Point a,Point b)
{
return (a-b)*(a-b);
}
//******二维凸包,int***********
const int MAXN = ;
Point list[MAXN];
int Stack[MAXN],top;
bool _cmp(Point p1,Point p2)
{
int tmp = (p1-list[])^(p2-list[]);
if(tmp > )return true;
else if(tmp == && dist2(p1,list[]) <= dist2(p2,list[]))
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k = ;
p0 = list[];
for(int i = ;i < n;i++)
if(p0.y > list[i].y || (p0.y == list[i].y && p0.x > list[i].x))
{
p0 = list[i];
k = i;
}
swap(list[k],list[]);
sort(list+,list+n,_cmp);
if(n == )
{
top = ;
Stack[] = ;
return;
}
if(n == )
{
top = ;
Stack[] = ; Stack[] = ;
return;
}
Stack[] = ; Stack[] = ;
top = ;
for(int i = ;i < n;i++)
{
while(top > &&
((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]])) <= )
top--;
Stack[top++] = i;
}
}
//旋转卡壳,求两点间距离平方的最大值
int rotating_calipers(Point p[],int n)
{
int ans = ;
Point v;
int cur = ;
for(int i = ;i < n;i++)
{
v = p[i]-p[(i+)%n];
while((v^(p[(cur+)%n]-p[cur])) < )
cur = (cur+)%n;
ans = max(ans,max(dist2(p[i],p[cur]),dist2(p[(i+)%n],p[(cur+)%n])));
}
return ans;
}
Point p[MAXN];
int main()
{
//freopen("in.txt","r",stdin) ;
int n;
while(scanf("%d",&n) == )
{
for(int i = ;i < n;i++)
list[i].input();
Graham(n);
for(int i = ;i < top;i++)p[i] = list[Stack[i]];
printf("%d\n",rotating_calipers(p,top));
}
return ;
}

poj 2187 N个点中输出2点的最大距离的平方的更多相关文章

  1. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  2. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  3. shell单引号中输出参数值

    因为在shell的单引号中,所有的特殊字符和变量都会变成文本,那么如果需要在字符串中输出变量值怎么办呢? 这里记录以下两种方法: 使用双引号 shell> X='parameter' shell ...

  4. python3中输出不换行

    python2中输出默认是换行的,为了抑制换行,是这么做的: print x, 到了python3中,print变成一个函数,这种语法便行不通了.用2to3工具转换了下,变成这样了: print(x, ...

  5. 在 ASP.NET MVC Web 应用程序中输出 RSS Feeds

    RSS全称Really Simple Syndication.一些更新频率较高的网站可以通过RSS让订阅者快速获取更新信息.RSS文档需遵守XML规范的,其中必需包含标题.链接.描述信息,还可以包含发 ...

  6. 在JSP页面中输出JSON格式数据

    JSON-taglib是一套使在JSP页面中输出JSON格式数据的标签库. JSON-taglib主页: http://json-taglib.sourceforge.net/index.html J ...

  7. MVC中如何在controller的action中输出JS到页面上

    MVC中如何在controller的action中输出JS到页面上 可以通过Http上下文对象(httpContext)就可以了,在Action中的HttpContext就是这个Action所指向的页 ...

  8. makefile中使用echo向文件中输出版本号和编译时间

    @echo "#define BUILD_TIME" `date +"%F_%H:%M:%S"` > buildTime_svnVer.h @echo & ...

  9. 在jsp中用一数组存储了数据库表中某一字段的值,然后在页面中输出其中的值。

    List<String> list = new ArrayList<String>();  String sql = "select userName from us ...

随机推荐

  1. Digia公司投资qt

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  2. layoutSubviews何时被调用

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 但是是用initWithFrame 进行初始化时,当rect的值不为CGRectZero时, ...

  3. JAVA-JSP动作

    动作元素基本上是预定义的功能.下表列出了可用的JSP动作 - 编号 动作 描述 1 jsp:include 在请求页面时包含一个文件. 2 jsp:useBean 查找或实例化一个JavaBean. ...

  4. java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别

    java.lang.System.arraycopy() 与java.util.Arrays.copyOf()的区别 一.java.lang.System.arraycopy() 该方法的声明: /* ...

  5. 【leetcode 简单】 第一百零九题 最小移动次数使数组元素相等

    给定一个长度为 n 的非空整数数组,找到让数组所有元素相等的最小移动次数.每次移动可以使 n - 1 个元素增加 1. 示例: 输入: [1,2,3] 输出: 3 解释: 只需要3次移动(注意每次移动 ...

  6. Linux基础-yum软件包管理

    任务目标:自定义yum仓库:createrepo,自定义repo文件,使用yum命令安装httpd软件包,卸载httpd软件包:yum –y remove 软件名 ,使用yum安装组件'KDE 桌面' ...

  7. webpack详解

    webpack是现代前端开发中最火的模块打包工具,只需要通过简单的配置,便可以完成模块的加载和打包.那它是怎么做到通过对一些插件的配置,便可以轻松实现对代码的构建呢? webpack的配置 const ...

  8. Computer Vision Resources

    Computer Vision Resources Softwares Topic Resources References Feature Extraction SIFT [1] [Demo pro ...

  9. 可能是最漂亮的Spring事务管理详解

    Java面试通关手册(Java学习指南):https://github.com/Snailclimb/Java_Guide 微信阅读地址链接:可能是最漂亮的Spring事务管理详解 事务概念回顾 什么 ...

  10. 当遇到not a dynamic executable时怎么做

    当我使用ldd查找Drcom所缺少的32为库的时候提示not a dynamic executable 最后网上找到答案 来自http://forum.ubuntu.org.cn/viewtopic. ...