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

Description

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill
between farmers and their cows. For simplicity, the world will be represented as a two-dimensional plane, where each farm is located at a pair of integer coordinates (x,y), each having a value in the range -10,000 ... 10,000. No two farms share the same pair
of coordinates.



Even though Bessie travels directly in a straight line between pairs of farms, the distance between some farms can be quite large, so she wants to bring a suitcase full of hay with her so she has enough food to eat on each leg of her journey. Since Bessie refills
her suitcase at every farm she visits, she wants to determine the maximum possible distance she might need to travel so she knows the size of suitcase she must bring.Help Bessie by computing the maximum distance among all pairs of farms.


Input

* Line 1: A single integer, N



* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm

Output

* Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other.

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; #define M 50005
struct node
{
double x,y;
}A[M],B[M]; double cmp(node a,node b) //先按X排序,其次按Y排序
{
if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
} double dis(node a,node b) //计算两点之间的距离
{
return (b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
} double chaji(node a,node b,node c) //叉积,推断方向
{
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
} int tubao(int n)
{
sort(A,A+n,cmp);
int m=0,i;
for(i=0;i<n;i++) //构建下凸包边
{
while(m>1 && chaji(B[m-2],B[m-1],A[i]) < 0)
m--;
B[m++]=A[i];
} int k=m;
for(i=n-2;i>=0;i--) //构建上凸包边
{
while(m>k && chaji(B[m-2],B[m-1],A[i]) < 0)
m--;
B[m++]=A[i];
} if(n>1) m--;
return m;
} int main()
{
int n;
cin>>n;
int i,j;
for(i=0;i<n;i++)
cin>>A[i].x>>A[i].y; double p=tubao(n);
__int64 max=0,q;
for(i=0;i<p;i++)
for(j=i+1;j<p;j++)
{
q=dis(B[i],B[j]);
if(max<q) max=q;
}
printf("%I64d\n",max); return 0;
}

POJ 2187 Beauty Contest 凸包的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  8. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

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

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

随机推荐

  1. Vmware ESX 5.0 安装与部署

    近期我公司部署了虚拟化,採购了两台Dell R710的server(CPU:64位双核,主频:2.4GHZ, 32G 内存.硬盘:2块300G做Riad 1.3块2T做Riad 5 .10块网卡),在 ...

  2. 关于方法的ref

    没有ref的方法时: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  3. [转] 8张图学习javascript

    学习的道路就是要不断的总结归纳,好记性不如烂笔头,so,下面将po出8张javascript相关的思维导图. 思维导图小tips:思维导图又叫心智图,是表达发射性思维的有效的图形思维工具 ,它简单却又 ...

  4. Python 第十一篇:开发堡垒机

    一:SqlAlchemy ORM ORM:Object Relational Mapping 对象关系映射是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 SQLAlchemy是 ...

  5. VS Code开发调试ASP.NET Core 1.0

    VS Code开发调试ASP.NET Core 1.0 使用VS Code开发调试ASP.NET Core 1.0,微软在今天凌晨发布了.NET Core 1.0,ASP.NET Core 1.0 与 ...

  6. Socket网络编程--FTP客户端(60篇socket博客,而且都比较简单、深入浅出)

    已经好久没有写过博客进行分享了.具体原因,在以后说. 这几天在了解FTP协议,准备任务是写一个FTP客户端程序.直接上干货了. 0.了解FTP作用 就是一个提供一个文件的共享协议. 1.了解FTP协议 ...

  7. 几个BCB例子

    http://blog.163.com/tab_98/blog/static/11924097201511274543737/

  8. C++成员变量与函数内存分配

    关于结构体和C++类的内存地址问题 C++类是由结构体发展得来的,所以他们的成员变量(C语言的结构体只有成员变量)的内存分配机制是一样的.下面我们以类来说明问题,如果类的问题通了,结构体也也就没问题啦 ...

  9. ViewPager控件的Demo

    1.主视图 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...

  10. 变相的取消Datagridview控件的选中状态

    思路:把每一列的文字颜色设为黑色,选中时候的背景为白色,颜色为黑色.每一列都这样设置,那么变相的达到了取消选中效果. 图: