POJ 2187 Beauty Contest( 凸包求最远点对 )
**链接:****传送门 **
题意:给出 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( 凸包求最远点对 )的更多相关文章
- POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 24283 Accepted: 7420 D ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- Beauty Contest(凸包求最远点)
http://poj.org/problem?id=2187 题意:求凸包上最远点距离的平方 思路:开始用旋转卡壳求的最远点,WA,改了好久..后来又改成枚举凸包上的点..AC了.. #include ...
- 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 (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- Django:Admin,Cookie,Session
一. Admin的配置 1.Admin基础设置 admin是django强大功能之一,它能够从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经 ...
- Linux-workqueue讲解
============= 参考 ============= 代码:linux-3.10.65/kernel/workqueue.c =============================== ...
- Spring事务管理 与 SpringAOP
1,Spring事务的核心接口 Spring事务管理的实现有许多细节,如果对整个接口框架有个大体了解会非常有利于我们理解事务,下面通过讲解Spring的事务接口来了解Spring实现事务的具体策略. ...
- POJ 2110
终于过了,SHIT,二分+DFS即可,二分区间,根据数字是否在区间内,变成迷宫题了.枚举第一个格子,二分上界,即可. #include <iostream> #include <cs ...
- Android Drawable 那些不为人知的高效使用方法
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/43752383,本文出自:[张鸿洋的博客] 1.概述 Drawable在我们平时的 ...
- [C#] 怎样分析stackoverflow等clr错误
有时候由于无限递归调用等代码错误,w3wp.exe会报错退出.原因是clr.exe出错了. 这样的错误比較难分析,由于C#代码抓不住StackOverflowException等异常. 处理方法是:生 ...
- [iOS翻译]《iOS7 by Tutorials》在Xcode 5里使用单元測试(上)
简单介绍: 单元測试是软件开发的一个重要方面.毕竟,单元測试能够帮你找到bug和崩溃原因,而程序崩溃是Apple在审查时拒绝app上架的首要原因. 单元測试不是万能的,但Apple把它作为开发工具包的 ...
- html与JacaScript中的重要思想:预留后路、向后兼容、js分离
以一个简单的web程序为例 详细设计模式请配合代码及凝视食用 <!DOCTYPE html> <!-- 1 预留退路:假设用户禁用了js.链接还能正常显示吗?(href) 2 分离j ...
- 2015.05.15,外语,学习笔记-《Word Power Made Easy》 02 “如何谈论医生”
包括Sessions 4-6: Prefix Person,nous,etc. Practice,etc. Adjective internus内部 internist [ɪn'tɝnɪst] n.内 ...
- 派生类地址比基类地址少4(CDerived对象的起始地址存放的是虚表指针vptr,也就是子类的第一项内容。接下来的是基类的成员变量,接下来再是自身的成员变量)
大家对虚表并不陌生,都知道每个含有虚函数的类对象都有1个虚指针,但是在现实使用中,却总是因为这而调试半天,才发现原来是虚指针惹的祸.我这几天在调试代码时候也中招了,我的问题是这样的,如下图,CTree ...