/*  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. debian/ubuntu 下ISE安装

    1. planAhead无法打开的问题 原因: debian中使用dash,跟planAhead使用的bash略有不同 解决: 将/bin/sh 的链接从dash改为bash 2. FPGA Edit ...

  2. 设置UIButton或者UILabel显示文字的行数

    需要在UIButton的titleLabel或者UILabel的text 字符串里面添加换行符号 “\n”,并且设置 UILabel的numberOfLines属性 栗子:行数要和“\n”的个数对应, ...

  3. dell交换机固件

    Upgrading the S4048-ON Dell Networking OS Image using the Dell Networking OS CLI Bare Metal Provisio ...

  4. php+redis window

    http://download.csdn.net/detail/qwfy326/6572443 wampserver2.2e-php5.3.13-httpd2.2.22-mysql5.5.24-x64

  5. 更改apache网站根目录导致localhost不能访问

    使用xampp或wamp安装完集成环境后,更改apache的网站根目录会导致localhost,localhost/phpmyadmin访问不到. 解决方法: 打开apache的配置文件:“../ap ...

  6. HTTP03--DNS知识

    一.域名解析过程 1. 浏览器检查自身缓存,缓存时间为几分钟到小时不等,通过设置TTL属性确定. 2. 若1未找到,则查OS缓存,如windows下的host文件,linux的/etc/hosts文件 ...

  7. 大数据存储:MongoDB实战指南——常见问题解答

    锁粒度与并发性能怎么样? 数据库的读写并发性能与锁的粒度息息相关,不管是读操作还是写操作开始运行时,都会请求相应的锁资源,如果请求不到,操作就会被阻塞.读操作请求的是读锁,能够与其它读操作共享,但是当 ...

  8. 公共代码参考(Volley)

    Volley 是google提供的一个网络库,相对于自己写httpclient确实方便很多,本文参考部分网上例子整理如下,以作备忘: 定义一个缓存类: public class BitmapCache ...

  9. Intel VT-x 基本概念

    看IaaS 资料时,捎带研究下硬件虚拟化,主要参考<基于intel VT-x 的Xen 全虚拟化实现>,<intel 开发手册 第三卷 19/20章> Intel VT 是in ...

  10. 【C语言学习】《C Primer Plus》第13章 文件输入/输出

    学习总结 1.文件函数原型1: FILE* fopen(char *filename, char *openmode);  //打开文件,返回文件指针 filename:文件名,更确切地说,是包含文件 ...