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. Sphnix

    Sphinx高性能的搜索引擎(简单.强大.实用) http://blog.csdn.net/lgm252008/article/details/5373354

  2. web.py入门

    官网介绍: web.py is a web framework for Python that is as simple as it is powerful. web.py is in the pub ...

  3. 用C语言写一个程序,得出当前系统的整形数字长(16位,32位,64位)等,不能使用sizeof()

    #include <iostream>#include <cmath>using namespace std; int main(){ int num = -1; unsign ...

  4. CreateThread与_beginthread, _beginthreadex创建线程的基本概念和区别(1)

    这三个函数都可以创建新的线程,但都是如何创建的呢?当然MSDN文档最权威: Creates a thread to execute within the virtual address space o ...

  5. [置顶] 吃论扯谈---吃货和Office 365订阅的关系

    什么事物都可以和吃联系起来,在女孩子穿裙子的季节这是一个悲伤的故事! 说明: :Office365是微软云计算产品之一,其采取订阅的方式,按人头*每月的方式付费,用户可以选择自己需要的服务 2:Off ...

  6. JSP TAG

    Jsp tag 能够灵活的将公共JSP代码模块化,类似<jsp:include page="./include.jsp"></jsp:include>等等. ...

  7. php下正则表达式整理

    一.正则表达式的历史背景 1,内容深厚的正则表达式 ^.+@.+\\..+$ 形式 字符串搜索与匹配的工具 2,应用范围 手机输入法 Windows文件搜索 linux 列出文件命令 网站用户注册,如 ...

  8. Codeforces 484A - Bits 二进制找1

    这题可以根据l, r 在二进制下的长度进行分类. l  的长度小于 r 的时候,有两种可能,一种是r 在二进制下是 1* 这种样子,故答案取 r : 一种是取答案为  (1LL << (r ...

  9. android 根据域名得到IP

    public static String GetInetAddress(String host) { String IPAddress = ""; InetAddress Retu ...

  10. c# 数据库编程(通过SqlCommand 执行DML语句)

    原来一直是java,python等语言,最近用c#语言,并编写数据库访问代码.使用了之后,这里总结下,分享下c#如何操作数据库. 在java等其它语言中,有一套标准的api来完成数据库访问,并且一般都 ...