**链接:****传送门 **

题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方

思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点


/*************************************************************************
> File Name: poj2187.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年05月08日 星期一 14时30分43秒
************************************************************************/ #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std; #define eps 1e-10
const int maxn = 50010;
struct point{ double x,y; }; double multi(point sp,point ep,point op){
return (sp.x-op.x)*(ep.y-op.y) >= (sp.y-op.y)*(ep.x-op.x);
}
bool operator < (const point &a,const point &b){
return a.y < b.y || ( a.y == b.y && a.x < b.x );
}
int Graham(point pnt[] , int n , point res[]){
int i , len , k = 0 , top = 1;
sort(pnt,pnt+n);
if( n == 0 ) return 0; res[0] = pnt[0];
if( n == 1 ) return 1; res[1] = pnt[1];
if( n == 2 ) return 2; res[2] = pnt[2];
for(int i = 2 ; i < n ; i++){
while( top && multi( pnt[i] , res[top] , res[top-1] ))
top--;
res[++top] = pnt[i];
}
len = top; res[++top] = pnt[n-2];
for(int i = n - 3 ; i >= 0 ; i--){
while( top!=len && multi( pnt[i] , res[top] , res[top-1] ))
top--;
res[++top] = pnt[i];
}
return top;
}
int Dist(point a,point b){
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
}
int main(){
int n;
while(~scanf("%d",&n)){
point pnt[maxn] , res[maxn];
for(int i = 0 ; i < n ; i++) scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
int num = Graham( pnt , n , res );
int dis = 0;
for(int i = 0 ; i < num ; i++){
for(int j = i+1 ; j < num ; j++){
dis = max( dis , Dist( res[i] , res[j] ) );
}
}
printf("%d\n",dis);
}
return 0;
}

POJ 2187 Beauty Contest( 凸包求最远点对 )的更多相关文章

  1. POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 24283   Accepted: 7420 D ...

  2. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

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

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

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

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

  5. Beauty Contest(凸包求最远点)

    http://poj.org/problem?id=2187 题意:求凸包上最远点距离的平方 思路:开始用旋转卡壳求的最远点,WA,改了好久..后来又改成枚举凸包上的点..AC了.. #include ...

  6. POJ 2187 Beauty Contest 凸包

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

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

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

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

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

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

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

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

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

随机推荐

  1. nyoj399-整除个数

    整除个数 时间限制:3000 ms  |  内存限制:65535 KB 难度:1 描述 1.2.3- -n这n(0<n<=1000000000)个数中有多少个数可以被正整数b整除. 输入 ...

  2. nyoj256-C小加之级数求和

    C小加 之 级数求和 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 最近,C小加 又遇到难题了,正寻求你的帮助. 已知:Sn= 1+1/2+1/3+-+1/n. 显然对 ...

  3. 【hihocoder 1312】搜索三·启发式搜索(启发式搜索写法)

    [题目链接]:http://hihocoder.com/problemset/problem/1312?sid=1092363 [题意] [题解] 定义一个A*函数 f = step+val 这里的v ...

  4. Warning: The following processes: -cmd.exe -java.exe are locking the following directory:

  5. HDU 3756

    很容易就想到把三维转化成了二维,求出点离Z轴的距离,把这个距离当成X坐标,Z轴当Y坐标,然后就变成了求一个直角三角形覆盖这些点 像上一题一样,确定斜率直线的时候,必定是有一点在线上的.于是,可以把直线 ...

  6. VC 获取控制台窗体的句柄(hWnd)

    在Windows中,句柄是一个系统内部数据结构的引用. 比如当你操作一个窗体.或说是一个Delphi窗体时,系统会给你一个该窗体的句柄,系统会通知你:你正在操作142号窗体.就此你的应用程序就能要求系 ...

  7. 我的php站点系统分析工具01

    出于后的工作需求.须要高速弄清楚整个php站点系统是怎样执行的.抱着试探的心态.写出了这个工具. 临时把它叫做"系统信息动态解析地图"吧,或许"系统信息图"更方 ...

  8. android TextView加边框

    为TextView加边框.须要在drawable建xml文件,里面设置shape来设置文本框的特殊效果. <?xml version="1.0" encoding=" ...

  9. Openwrt 软件安装源

    进入http://downloads.openwrt.org/barrier_breaker/14.07/站点找到符合处理器型号的软件源.參考下图: watermark/2/text/aHR0cDov ...

  10. [Erlang危机](4.2)Remsh

    原创文章,转载请注明出处:server非业余研究http://blog.csdn.net/erlib 作者Sunface 联系邮箱:cto@188.com Remsh There's a mechan ...