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

题意:给出 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. javaScript原型、闭包和异步操作

    同学们,这篇博客有点水了,并不是说我不想写这块的内容,是因为查了很多资料,看了很多帖子之后,发现园内王福朋老师写的这系列文章真的很好,他的这系列的博客我已经看了3.4遍了,每一次都有新的收获,我可写不 ...

  2. POJ 2377 Bad Cowtractors( 最小生成树转化 )

    链接:传送门 题意:给 n 个点 , m 个关系,求这些关系的最大生成树,如果无法形成树,则输出 -1 思路:输入时将边权转化为负值就可以将此问题转化为最小生成树的问题了 /************* ...

  3. jenkins 打包 springboot

    遇到的坑 jdk maven  可以自己配置 也可以让jenkins生成 jenkins创建的项目打的包在  /var/lib/jenkins/jobs/ 需要手动去下载pom中的jar  吧pom复 ...

  4. Oracle数据库性能优化基础

    1.数据处理分类OLTP,OLAP 2.Oracle特性 3.数据库优化方法论/原则 方法论:自顶向下优化和自底向上优化 3.1 自顶向下优化 3.2 自底向上优化 对于多年的老系统出现性能问题时,就 ...

  5. POJ 4786 Fibonacci Tree

    Fibonacci Tree Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

  6. PL/SQL控制语句

    本节要点: l  选择结构控制语句 if条件控制语句 Case语句 l  循环结构控制语句 基本loop循环 for循环 while循环 嵌套循环 PL/SQL既然是面向过程的编程语言,那么它就有针对 ...

  7. Maven错误-Missing artifact com.sun:tools:jar:1.5.0:system 解决方式

    1.Missing artifact com.sun:tools:jar:1.5.0:system Could not resolve dependencies for project com.ifl ...

  8. 王立平--split字符串切割

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  9. navicate11不能激活的问题

    navicate11不能激活的问题 学习了:http://blog.csdn.net/sanbingyutuoniao123/article/details/52589678 不要安装在系统盘,如果安 ...

  10. RDIFramework.NET V2.9版本号 WinFom部分新增与修正的功能

    RDIFramework.NET  V2.9版本号 WinFom部分新增与修正的功能 转眼间RDIFramework.NET框架走了快6个年头了,随着一个版本号一个版本号的升级改造,如今已经越来越完美 ...