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

题意:给出 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. BZOJ 2333 [SCOI2011]棘手的操作 (可并堆)

    码农题.. 很显然除了两个全局操作都能用可并堆完成 全局最大值用个multiset记录,每次合并时搞一搞就行了 注意使用multiset删除元素时 如果直接delete一个值,会把和这个值相同的所有元 ...

  2. BZOJ 1901 Dynamic Rankings (整体二分+树状数组)

    题目大意:略 洛谷传送门 这道题在洛谷上数据比较强 貌似这个题比较常见的写法是树状数组套主席树,动态修改 我写的是整体二分 一开始的序列全都视为插入 对于修改操作,把它拆分成插入和删除两个操作 像$C ...

  3. yii2-dingtalk 钉钉群机器人

    说明 群机器人是钉钉群的高级扩展功能.群机器人可以将第三方服务的信息聚合到群聊中,实现自动化的信息同步.目前,大部分机器人在添加后,还需要进行Webhook配置,才可正常使用(配置说明详见操作流程中的 ...

  4. Java工具类使用注意事项

    (以下摘自阿里巴巴Java开发手册) 1. [强制]获取单例对象需要保证线程安全,其中的方法也要保证线程安全. 说明:资源驱动类.工具类.单例工厂类都需要注意. 5. [强制]SimpleDateFo ...

  5. String 字符串的追加,数组拷贝

    package chengbaoDemo; import java.util.Arrays; /** *需求:数组的扩容以及数据的拷贝 *分析:因为String的实质是以字符数组存储的,所以字符串的追 ...

  6. Apache负载均衡与Tomcat集群配置学习(Windows环境)

    本文主要参考自http://www.iteye.com/topic/985404?dhcc,经由实际操作配置操并记录而成. 由于最近的一个Java开发项目用到了Tomcat中间件作为web服务器,刚开 ...

  7. HDU 4345

    细心点想,就明白了,题目是求和为N的各数的最小公倍数的种数.其实就是求N以内的各素数的不同的组合(包含他们的次方),当然,是不能超过N的.用Dp能解决.和背包差不多. #include <ios ...

  8. [HTML5] Handle Offscreen Accessibility

    Sometime when some component is offscreen, but still get focus when we tab though the page. This can ...

  9. 【手势交互】6. 微动VID

    中国 天津 http://www.sharpnow.com/ 微动VID是天津锋时互动科技有限公司开发的中国Leap Motion. 它能够识别并跟踪用户手部的姿态.包含:指尖和掌心的三维空间位置:手 ...

  10. CF 567D(One-Dimensional Battle Ships-二分)

    D. One-Dimensional Battle Ships time limit per test 1 second memory limit per test 256 megabytes inp ...