poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* 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(凸包求解多节点的之间的最大距离)的更多相关文章
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
随机推荐
- XPath使用示例
1.查找空节点//*[not(text())] 表示内容为空的节点//*[count(*)=0] 表示没有子节点的节点"//*[count(*)=0 and n ...
- 【整理】--C++三种参数传递方式
在C++中,共有三种参数传递方式: 按值传递(pass by value) 地址传递(pass by pointer) 引用传递(pass by reference) (1)按值传递的过程为:首先计算 ...
- MySQL 升级详细步骤 (包括 Percona)
MySQL 升级步骤 MySQL 5.1.72 升级到 MySQL 5.5.36 鉴于我在升级的时候遇到的麻烦问题,我觉得有必要把一些细节说清楚,免得引起误解了.感觉官方文档上的升级步骤写的比较简单, ...
- SqlServerProxy的一些资料
SqlServerProxy的一些资料 下载地址:http://files.cnblogs.com/files/lyhabc/SqlServerProxy.rar 1.特性及实现原理 SqlServe ...
- 微信公共平台开发-(.net实现)1--成为开发者
刚换了个新环境,哎这都快一个月了,还没适应过来,还是怀念老地方呀.老板让开发一个基于微信平台的开发项目,而且是用net实现.当时就蒙了,微信就用了一会个人赶脚不好,所以果断不用,现在让开发,而且查了一 ...
- SqlServer2012 数据库的同步问题汇总
1.当订阅由发布服务器集中管理时正常,而把这些订阅分由订阅服务器管理,在发布服务器初始化订阅时,这些订阅就会出现无法访问某地址的问题,即使添加Everyone的完全控制权限也无用. 2.SqlServ ...
- .NET面试题解析(11)-SQL语言基础及数据库基本原理
系列文章目录地址: .NET面试题解析(00)-开篇来谈谈面试 & 系列文章索引 本文内容涉及到基本SQL语法,数据的基本存储原理,数据库一些概念.数据优化等.抱砖引玉,权当一个综合复习! ...
- 人人都是 DBA(IX)服务器信息收集脚本汇编
什么?有个 SQL 执行了 8 秒! 哪里出了问题?臣妾不知道啊,得找 DBA 啊. DBA 人呢?离职了!!擦!!! 程序员在无处寻求帮助时,就得想办法自救,努力让自己变成 "伪 DBA& ...
- 根据Excel的内容和word模板生成对应的word文档
Sub setname() Dim I As Integer Dim pspname As String Dim pspnumber As String Dim path As String Dim ...
- Linux下Java开发环境搭建—CentOS下Eclipse的安装教程
据了解,在Linux下的Java开发很多时候都比较喜欢使用vim + 插件,反而很少使用Eclipse,但是我是第一次使用Linux来进行Java编程,就什么都体验下啦,好啦,废话不多说,直接开始啦. ...