/*  poj 2187 Beauty Contest
凸包:寻找每两点之间距离的最大值
这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法!
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; struct Point{
Point(){}
Point(int x, int y){
this->x=x;
this->y=y;
}
int x, y; static int cross(Point a, Point b){
return a.x*b.y - a.y*b.x;
} static int dist(Point a, Point b){
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} Point operator -(Point tmp){
return Point(x-tmp.x, y-tmp.y);
}
}; bool cmp(Point a, Point b){
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
} Point p[];
int ch[];
int n; int main(){
int i;
while(scanf("%d", &n)!=EOF){
for(i=; i<n; ++i)
scanf("%d%d", &p[i].x, &p[i].y);
sort(p, p+n, cmp);
int m=;
//求下凸包, 如果某一个点不在线段之内,向量的叉积必定是<=0;
for(i=; i<n; ++i){
while(m> && Point::cross(p[ch[m-]]-p[ch[m-]], p[i]-p[ch[m-]])<=) m--;
ch[m++]=i;
}
//为啥求上凸包的时候,坐标的从n-2开始:因为n-1点一定是在下凸包中的(因为它的横坐标最大,必然是包含其他节点的)
int k=m;
for(i=n-; i>=; --i){
while(m>k && Point::cross(p[ch[m-]]-p[ch[m-]], p[i]-p[ch[m-]])<=) m--;
ch[m++]=i;
}
--m;
int maxD=-, j, d;
for(i=; i<m; ++i)
for(j=i+; j<=m; ++j)
if(maxD < (d=Point::dist(p[ch[i]], p[ch[j]])))
maxD=d;
printf("%d\n", maxD);
}
return ;
}

poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)的更多相关文章

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

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

  2. POJ 2187 Beauty Contest 凸包

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

  3. POJ 2187 Beauty Contest [凸包 旋转卡壳]

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

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

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

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

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

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

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

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

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

  8. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

  9. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

随机推荐

  1. Java中HashMap等的实现要点浅析

    @南柯梦博客中的系列文章对Jdk中常用容器类ArrayList.LinkedList.HashMap.HashSet等的实现原理以代码注释的方式给予了说明(详见http://www.cnblogs.c ...

  2. Replication的犄角旮旯(四)--关于事务复制的监控

    <Replication的犄角旮旯>系列导读 Replication的犄角旮旯(一)--变更订阅端表名的应用场景 Replication的犄角旮旯(二)--寻找订阅端丢失的记录 Repli ...

  3. maven安装nexus私服

    从nexus官网下载Nexus Repository Manager OSS 2.x的安装包:nexus-2.14.1-01-bundle.tar.gz,3.x版本需要jdk8及以上 解压 tar x ...

  4. Android(5)— Mono For Android 两个功能型外包

    0.前言 距上一篇博文貌似很久了,其中原因种种,归根结底是自己没有坚持好,没有静下心来归纳总结,希望从这一刻起每个月坚持写两篇.(哈哈,突然想起老师说起一句话, 晚上在被窝里悄悄发誓好好学习,第二天涛 ...

  5. 高性能网站架构设计之缓存篇(1)- Redis的安装与使用

    一.什么 Redis REmote DIctionary Server,简称 Redis,是一个类似于Memcached的Key-Value存储系统.相比Memcached,它支持更丰富的数据结构,包 ...

  6. Xamarin.Android之UI Test简单入门

    一.前言 相信Xamarin免费之后会有更多的人加入进来,这也是我一直以来最希望看到的事,更多的人加入到这个社区中,为这个社区贡献自己的一份力量,国内当前还没有一个比较正规或者说是名气比较大的Xama ...

  7. 开始VS 2012中LightSwitch系列的第3部分:我该选择哪一个屏幕模板

    [原文发表地址]  Beginning LightSwitch in VS 2012 Part 3: Screen Templates, Which One Do I Choose? [原文发表时间] ...

  8. 设计模式之美:Role Object(角色对象)

    索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):Role Object 的示例实现. 意图 通过明确地附加角色对象到目标对象中,以使对象可以适配不同的客户需求.每个角色对象都代 ...

  9. var与this,{}与function 小记

    JavaScript var是用来定义一个变量,this常用来定义或调用一个属性或方法.但是在全局范围内,this和var定义变量是等价的. window console.log('window:', ...

  10. Wix 安装部署教程(七) 获取管理员权限

    应用程序运行的时候,难免会读写文件,产生新的数据.但Program Files下的文件是不能随便更改,Win7下如果没有权限,将会被拒绝.我现在有两种方式,一种是将数据路径移到Program Data ...