POJ2187 Beauty Contest
Description
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
* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm
Output
Sample Input
4
0 0
0 1
1 1
1 0
Sample Output
2
Hint
Source
//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的更多相关文章
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...
- poj2187 Beauty Contest (凸包 + 旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38349 Accepted: 11851 ...
- POJ2187 Beauty Contest (旋转卡壳算法 求直径)
POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- POJ2187 Beauty Contest(旋转卡壳)
嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- 【POJ】2187 Beauty Contest(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
随机推荐
- unity3d Aniso Level 摄像机近地面清楚,远地面模糊
设置方法 选中贴图 在属性面板,拖动Aniso Level的值从0~9改变,值越大贴图越清晰,但是消耗也变大,文档说会造成显卡消耗,一般只用在地面上,其他地方没必要 遇到的问题 但是打包到Ipod上面 ...
- 3D跑酷遇到的问题
前言 项目名称:3D跑酷项目 写作目地:使用Asset Server进行多人协作开发过程中,记录遇到的问题 问题1:UIAtlas无法自动更新 描述:NGUI的Atlas图集(图片)无法自动更新 后果 ...
- centos下pip安装mysql_python
今天在使用pip安装mysql_python时,遇到一些问题,现记录下来. 1.执行pip install mysql-python时,报错 Running setup.py egg_info for ...
- java 21 - 10 文本文件和集合之间互相存储数据
有时候,我们会遇到单独写入数据到文本文件的情况.比如: 需求:把ArrayList集合中的字符串数据存储到文本文件 分析: A:ArrayList集合中存储的是String类 B:要存储的文件是文本文 ...
- 关于phpmyadmin #1045无法登陆服务器的问题
修改/home/wwwroot/phpmyadmin/libraries/config.default.php 文件,找到下面两行 $cfg['Servers'][$i]['nopassword'] ...
- 分享一个刷网页PV的python小脚本
下面分享一个小脚本,用来刷网页PV. [root@huanqiu ~]# cat www.py #!/usr/bin/python# coding: UTF-8import webbrowser as ...
- center
center标签对其包围的文本进行水平居中处理
- 混合语言编程:启用CLR(公共语言运行时编译)让C#调用C++
前言 关于混合C#和C++的编程方式,本人之前写过一篇博客(参见混合语言编程:C#使用原生的Directx和OpenGL),在之前的博客中,介绍了在C#的Winform和WPF下使用原生的Direct ...
- CentOS 7 安装桌面环境
首先进入要使用root权限: 使用 yum grouplist可以看现在的安装情况以及支持哪些软件包. 使用 yum groupinstall "GNOME Desktop" &q ...
- 在页面上以消息束的形式同时抛出多个DialogMessage
com.sun.java.util.collections.ArrayList exceptions = new com.sun.java.util.collections.ArrayList(); ...