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轴.. 然后本题数据 ...
随机推荐
- java 20 - 5 字节输出流写出数据的一些方法
首先回顾下 字节输出流操作步骤: A:创建字节输出流对象 B:调用write()方法 C:释放资源 创建字节流输出对象 FileOutputStream fos = new FileOutput ...
- 异常:NSException和NSAssert的简单使用
//断言 - (void)NSAssert_Test:(NSString *)string{ NSAssert(string == nil, @"string == kong or nil& ...
- PHP openssl加密扩展使用总结
1.检查服务器是否已安装了openssl组件,没有则先安装好 openssl version [-a] 2.对称加密 查询openssl支持的对称加密算法 openssl_get_cipher_met ...
- 21Spring_JdbcTemplatem模板工具类的使用——配置文件(连接三种数据库连接池)
上一篇文章提到过DriverManagerDataSource只是Spring内置的数据库连接池,我们可选的方案还有c3p0数据库连接池以及DBCP数据库连接池. 所以这篇文章讲一下上面三种数据库连接 ...
- 传递消息--第三方开源--EventBus的简单使用
EventBus下载地址:https://github.com/greenrobot/EventBus MyEvent: package com.zzw.testeventbus; public cl ...
- [tools]tcp/udp连通性测试
一 端口连通性测试意义 测试网络端口可达性,确保给某些使用特定端口的app做链路连通性检测.使它们能够正常的运行起来. 二 法1 使用newclient发包,彼端tcpdump抓包观察是否能收到包 ...
- 完成一个MVC+Nhibernate+Jquery-EasyUI信息发布系统
一.最近学习了Jquery-EasyUI框架,结合之前用过的MVC3+Nhibernate做一个信息发布系统,对工作一年半的自己做一个总结吧!(也正好 供初学者学习!) 二.先上截图(系统简介),让大 ...
- 20135316王剑桥 linux第七周课实验笔记
第十章.程序间的交互和通信 输入/输出(I/O)是在主存和外部设备之间拷贝数据的过程.输入操作是从I/O设备拷贝数据到主存,而输出操作是从主存拷贝数据到I/O设备. 输入:从I/O拷贝到主存,输出:从 ...
- JS模拟Alert与Confirm对话框
这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听.,样式用了Css3的一些特性. 调用方式则为: //Alert Alert.show('我警告你哦~'); //Confir ...
- IT男的”幸福”生活"续9
世界上最容易失去的便是时间了,我们总是蓦然回首,而时间早已流去. 曾经的种种,时时刻刻在我们脑中出现,让我们感到开心,快乐,幸福等. 有时好想有一种动冲,回到过去,再感受一下心中的那份触动. 又一年过 ...