/*  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.lang.RuntimeException: Method setUp in android.test.ApplicationTestCase not mocked. See http://g.co/androidstudio/not-mocked for details.

    解决: build.gradle里加入: android { testOptions { unitTests.returnDefaultValues = true } }

  2. LintCode 392 House Robber

    // Ref: https://segmentfault.com/a/1190000003811581// Ref: http://www.cnblogs.com/grandyang/p/438363 ...

  3. LintCode 111 Climbing Stairs

    这道题参考了这个网址: http://blog.csdn.net/u012490475/article/details/48845683 /* 首先考虑边界情况,当有1层时,有一种方法. 然后再看2层 ...

  4. CentOS7 服务器 JDK+TOMCAT+MYSQL+redis 安装日志

    防火墙配置(参考 CentOS7安装iptables防火墙) 检查是否安装iptables #先检查是否安装了iptables service iptables status #安装iptables ...

  5. wrHDL编译中软核代码初始化及编译耗时长的问题

    问题的提出整个WR的ISE工程比较大,编译时间很长,导致开发效率低.通过分析发现,ISE在综合的时候大量的时间都花在了初始化DPRAM上.调研发现Xilinx提供了BMM文件和DATA2MEM工具,可 ...

  6. windows management instrumentation服务未启动-解决脚本

    桌面新建.txt文件 将以下代码放入 保存为.bat文件 执行即可 @echo on cd /d c:\temp if not exist %windir%\system32\wbem goto Tr ...

  7. WinAPI: GetKeyNameText - 根据键盘消息获取按键名称

    ;  Canvas.Font.Style := [fsBold];  Canvas.Font.Color := clRed;  Canvas.Brush.Color := clWhite;..] of ...

  8. 初学python里的yield send next

    今天看书的时候突然看到这个想起来一直没有怎么使用过send和next试了一下 发现了一个诡异的问题 import math def get_primes(start): while 1 : if is ...

  9. ENode 1.0 - 框架的总体目标

    开源地址:https://github.com/tangxuehua/enode 本文想介绍一下enode框架要实现的目标以及部分实现分析思路剖析.总体来说enode框架是一个基于cqrs架构和消息驱 ...

  10. Visual Studio 2015 RC版官方下载(ISO)

    微软Build2015开发者大会发布了下代开发套件Visual Studio 2015 RC候选版,覆盖企业版.专业版以及免费授权的Community社区版,原生支持开发通用型Windows Apps ...