给定点集的最远两点的距离。

先用graham求凸包。旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径。

ps:旋转卡壳算法的典型运用

http://blog.csdn.net/hanchengxi/article/details/8639476

 #include <cstdio>
#include <cmath>
#include <algorithm>
#define sqr(x) (x)*(x)
#define N 50001
using namespace std;
struct P{
int x,y;
}p[N],q[N];
int n,ans,top;
int dis2(P a,P b){
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
int xmult(P a,P b,P o){
return (a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
}
int cmp(P a,P b){
return xmult(a,b,p[])>||xmult(a,b,p[])==&&dis2(a,p[])<dis2(b,p[]);
}
void graham(){
sort(p+,p++n,cmp);
q[]=p[],q[]=p[];
top=;
for(int i=;i<=n;i++){
while(xmult(q[top],p[i],q[top-])<=&&top>)top--;
q[++top]=p[i];
}
}
void qiake(){
q[top+]=q[];
int now=;
for(int i=;i<=top;i++){
while(xmult(q[i+],q[now],q[i])<xmult(q[i+],q[now+],q[i]))
{
now++;
if(now>top)now=;
}
ans=max(ans,dis2(q[now],q[i]));
}
}
int main() {
scanf("%d",&n);
int t=;
for(int i=;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
if(p[t].y>p[i].y||p[t].y==p[i].y&&p[t].x>p[i].x)t=i;
}
swap(p[],p[t]);
graham();
qiake();
printf("%d",ans);
return ;
}

【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)的更多相关文章

  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. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  4. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  5. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

  6. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  7. ●POJ 2187 Beauty Contest

    题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...

  8. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  9. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  10. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

随机推荐

  1. java 27 - 1 反射之 类的加载器

    说到反射,首先说类的加载器. 类的加载: 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. 加载: 就是指将class文件读入内存,并为之 ...

  2. uva10160 Servicing Stations

    The input consists of more than one description of town (but totally, less than ten descriptions). E ...

  3. Objective-C 命名规范

    http://www.tuicool.com/articles/ERvUbmR 1. 如果方法的返回值是新创建的,那么方法名的首个词应是返回值类型,除非前面还有修饰语如 localizedString ...

  4. 初识html5 File API实现带有进度提示的文件上传

    Html5终于解决了上传文件的同时显示文件上传进度的老问题.现在大部分的网站用Flash去实现这一功能,还有一些网站继续采用Html <form>with enctype=multipar ...

  5. Meet Python: little notes 2

    From this blog I will turn to Markdown for original writing. Source: http://www.liaoxuefeng.com/ ♥ l ...

  6. Java 基础命名空间

    java.lang (提供利用 Java 编程语言进行程序设计的基础类)java.lang.annotation(提供了引用对象类,支持在某种程度上与垃圾回收器之间的交互)java.lang.inst ...

  7. R统计分析处理

    [翻译]Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么? 阅读目录 0.前言 1.集成开发环境 2.语法 3.数据操作 4.图形显示 5.HTML部件 ...

  8. 别出心裁的Linux系统调用学习法

    别出心裁的Linux系统调用学习法 操作系统与系统调用 操作系统(Operating System,简称OS)是计算机中最重要的系统软件,是这样的一组系统程序的集成:这些系统程序在用户对计算机的使用中 ...

  9. MyBatis拦截器原理探究

    MyBatis拦截器介绍 MyBatis提供了一种插件(plugin)的功能,虽然叫做插件,但其实这是拦截器功能.那么拦截器拦截MyBatis中的哪些内容呢? 我们进入官网看一看: MyBatis 允 ...

  10. 高性能JavaScript 达夫设备

    前言 在<高性能JavaScript>一书的第四章算法和流程控制中,提到了减少迭代次数加速程序的策略—达夫设备(Duff's device).达夫设备本身很好理解,但是其效果是否真的像书中 ...