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

Hint

Farm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2) 

Source

 
 
正解:凸包
解题报告:
   2016年北京大学信息学奥赛训练营上机考核第二场 A题
       大致题意是求最远点对
   碰到这样一道水题,我居然没有AC,在考场上真是农飞了。话说pku尽考原题
       其实标准解法是先求凸包,再旋转卡壳。然而数据水,求完凸包,然后直接凸包上面跑暴力就可以了。
       考场上面没有调出来凸包,真是gi 
 
 
 //It is made by jump~
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
const int MAXN = ;
int n,m;
LL ans; struct node{
int x,y;
node(int x=,int y=):x(x),y(y) { }
bool operator < (const node a)const{
if(a.x==x) return a.y>y;
return a.x>x;
}
node operator - (const node& o){
return node(x-o.x, y-o.y);
}
}jump[MAXN],ch[MAXN*]; int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} int cross(node a,node b){
return a.x*b.y-a.y*b.x;
} LL dis(node a,node b){
return (LL) ( (LL)(a.x-b.x)*(LL)(a.x-b.x) + (LL)(a.y-b.y)*(LL)(a.y-b.y) );
} int main()
{
n=getint();
//for(int i=1;i<=n;i++) jump[i].x=getint(),jump[i].y=getint();
for(int i=;i<=n;i++)
{
int x=getint(),y=getint();
jump[i]=node(x,y);
}
sort(jump+,jump+n+); m=;
for(int i=;i<=n;i++)
{
while(m> && cross(ch[m-]-ch[m-],jump[i]-ch[m-])<=) m--;
ch[m++]=jump[i];
}
int k=m;
for(int i=n-;i>=;i--)
{
while(m>k && cross(ch[m-]-ch[m-],jump[i]-ch[m-])<=) m--;
ch[m++]=jump[i];
} if(n>) m--; ans=;
for(int i=;i<=m;i++)
for(int j=i+;j<=m;j++){
LL now=dis(ch[i],ch[j]);
if(now>ans) ans=now;
}
printf("%lld",ans);
return ;
}

POJ2187 Beauty Contest的更多相关文章

  1. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  2. POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!

     凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...

  3. poj2187 Beauty Contest (凸包 + 旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38349   Accepted: 11851 ...

  4. POJ2187 Beauty Contest (旋转卡壳算法 求直径)

    POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...

  5. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  6. POJ2187 Beauty Contest(旋转卡壳)

    嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...

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

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

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

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

  9. 【POJ】2187 Beauty Contest(旋转卡壳)

    http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...

随机推荐

  1. Unity抗锯齿

    Unity抗锯齿设置是针对模型,对模型的阴影的锯齿设置无效,不知道我这样的理解是否正确. 遇到的问题 而我是要对灯光照射在模型上产生的阴影进行抗锯齿,暂时还未研究出解决方案,希望知道的朋友告知一声. ...

  2. 十个Flex/Air疑难杂症及解决方案简略

    十个Flex/Air疑难杂症及解决方案简略 转自http://blog.sban.us/40.html 最近去一家台企,对方给我出了十道“难道”:在TileList中如果選擇檔過多,會出現捲軸,當拖動 ...

  3. 判断变量是否为json对象

    var m ={a:'A'}; if(typeof m == 'object' && JSON.stringify(m).indexOf('{') == 0){//判断变量m是不是js ...

  4. docker中清理冗余的image,container

    1) 首先进入超级用户模式 [root@docker ~]# sudo su2) 删除container ( container运行时是不能删除的 )首先停止container [root@docke ...

  5. Android studio disign 问题

    有些低配置的电脑使用android studio 写xml的时候,disign会一直处于rendering,有可能是xml使用的图片过大导致渲染不出来

  6. [转]的C#实现三维数字地形漫游(基于Irrlicht)

    马省轩  任丽娜 摘  要:本文采用C#编程语言,利用Irrlicht三维图形引擎实现了三维数字地形的漫游.为三维数字地形显示提供了较易实现的解决方案. 关键词:C#   高度图 Irrlicht引擎 ...

  7. python 转 exe -- py2exe库实录

    本文基于windows 7 + python 3.4 把python程序打包成exe,比较好用的库是py2exe 其操作步骤是: --> 编写python程序 --> 再额外编写一个导入了 ...

  8. C#操作JSON

    http://www.cnblogs.com/LiZhiW/p/3624729.html C#操作JSON 1. .NET对JSON的支持介绍............................. ...

  9. 在matlab和opencv中分别实现稀疏表示

    在本文中,稀疏表示的原理不再具体讲解,有需要的同学请自行百度. 本文采用OMP算法来求解稀疏系数.首先随机生成字典数据和待测试数据 字典数据: dic =[ 6, 7, 9, 9, 7, 0, 6, ...

  10. js copy

    Javascript 实现复制(Copy)动作方法大全 投稿:hebedich 字体:[增加 减小] 类型:转载 时间:2014-06-20我要评论 现在浏览器种类也越来越多,诸如 IE.Firefo ...