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 ...
随机推荐
- android开发学习之Layer List
Android中drawable分为Bitmap File.Nine-Patch File.Layer List.State List.Level List.Transition Drawable.I ...
- Jquery的multifile使用随记
1.多文件上传: 2.如上几个验证不重复,和限制上传数量的验证显示的是英文,改成中文文本时,如果不用国标解码,到时候提示框会出现乱码现象.所以一般需要中文显示的时候,我们应该这样做: 拿denied做 ...
- iOS一些关于日历的问题
int CalculateDays(int ys, int ms, int ds, int ye, int me, int de) { int days = CalcYearRestDays(ys, ...
- Paypal支付接口
先吐槽一下,国外的创业环境真的远远好于国内的创业环境. vps便宜,网络质量好,没有各种政策监管,各种便捷的金融工具.这其中就包括paypal. Paypal 支持两种付款方式,信用卡+paypal注 ...
- UNET学习笔记2 - 高级API(HLAPI)
高级API是在实时传输低级API基础上建立起来的,为多人游戏提供大量通用的组件.通过HLAPI开发者仅需少量的工作就可以搭建多人联网游戏. HLAPI 使用命名空间 UnityEngine.Netwo ...
- svn忽略eclipse自动生成的文件
工程目录下右键,选择“TortoiseSVN”——“Settings”菜单 选择“General”,在“Global ignore pattern”输入框的最前面添加 .settings .class ...
- NativeScript 也能开发桌面应用 (nativescript-dotnet-runtime)
自从看了NativeScript就甚是喜欢,心想要是也能开发桌面应用该多好.求人不如求己,开源组件很强大,差不多组装一下就行了,说干就干. Javascript 引擎用 Jint , 纯C#实现,集成 ...
- dex分包变形记
腾讯Bugly特约作者:李金涛 一.背景 就在项目灰度测试前不久,爆出了在 Android 3.0以下手机上安装时出现 INSTALL _ FAILED_DEXOPT,导致安装失败.这一问题意味着项目 ...
- UWP?UWP! - Build 2015有些啥?(1)
UWP?UWP! - Build 2015有些啥? Build 2015圆满落幕了,不知大家有多少人刷夜看了直播呢?不管怎么说,想必各位都很好奇在这场微软开发者盛宴上,Microsoft又发布了什么令 ...
- (文摘)彻底理解webservice SOAP WSDL
WebServices特点介绍 WebServices 提供一个建立分布式应用的平台,使得运行在不同操作系统和不同设备上的软件,或者是用不同的程序语言和不同厂商的软件开发工具开发的软件,所有可能的已开 ...