poj 2187:Beauty Contest(旋转卡壳)
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 32708 | Accepted: 10156 |
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
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
const double eps=1e-;
int top,N;
int ANS;
struct P{
int x,y;
friend P operator-(P a,P b){
P t; t.x=a.x-b.x; t.y=a.y-b.y;
return t;
}
friend double operator*(P a,P b){
return a.x*b.y-b.x*a.y;
}
}p[],s[]; inline int dis(P a,P b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool operator<(P a,P b){
int t=(a-p[])*(b-p[]);
if(abs(t)<=eps) return dis(a,p[])<dis(b,p[]);
return t>;
}
inline void graham(){
int tmp=;
for(int i=;i<=N;i++){
if(p[i].y<p[tmp].y||(p[i].y==p[tmp].y&&p[i].x<p[tmp].x)) tmp=i;
}
swap(p[],p[tmp]);
sort(p+,p+N+);
s[]=p[]; s[]=p[]; top=;
for(int i=;i<=N;i++){
while(top>&&(p[i]-s[top-])*(s[top]-s[top-])>=) top--;
s[++top]=p[i];
}
}
inline int RC(){
int q=; ANS=;
s[top+]=p[];
for(int i=;i<=top;i++){
while((s[i+]-s[i])*(s[q+]-s[i])>(s[i+]-s[i])*(s[q]-s[i])) q=q%top+;
ANS=max(ANS,max(dis(s[q],s[i+]),dis(s[q],s[i])));
}
return ANS;
}
int main(){
scanf("%d",&N);
for(int i=;i<=N;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
graham();
printf("%d",RC());
return ;
}
poj 2187:Beauty Contest(旋转卡壳)的更多相关文章
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
随机推荐
- var ie = !-[1,], [^\x00-\xff]
var ie = !-[1,]: 这句代码在IE9之前曾被称为世界上最短的IE判定代码.代码虽短但确包含了不少javascript基础知识在里面.在这个例子中代码执行时会先调用数组的toString( ...
- Oracle 删除表
drop table books;的指令会将表放到回收站里, 用 flashback table "BIN$1Oiy3qm/QJubov1BwBUOgw==$0" to befor ...
- Uncaught TypeError: Cannot set property 'value' of null
w拼写多一个空格导致. document.getElementById(winput_id).value = value; http://stackoverflow.com/questions/161 ...
- Storm-源码分析-Topology Submit-Task-TopologyContext (backtype.storm.task)
1. GeneralTopologyContext 记录了Topology的基本信息, 包含StormTopology, StormConf 已经从他们推导出的, task和component, co ...
- 并发编程 - 进程 - 1.互斥锁/2.模拟抢票/3.互斥锁与join区别
1.互斥锁: 互斥锁:Lock 原理就是把并发变成串行,一个一个运行,不错乱,但效率低 保证多个进程修改一块数据时,大家是一个一个修改,不错乱 mutex.acquire() mutex.releas ...
- ssh登录服务器
ssh -i /home/zhangsuosheng/mykey.pub myusername@111.111.111.111
- 由link和@import的区别引发的CSS渲染杂谈
我们都知道,外部引入 CSS 有2种方式,link标签和@import. 它们有何本质区别,有何使用建议,在考察外部引入 CSS 这部分内容时,经常被提起. 如今,很多学者本着知其然不欲知其所以然的学 ...
- Java 输入/输出流
1. 编码问题 在介绍输入输出之前我们先介绍下关于编码的一些基本知识点.当一个文件里既有中文字符又有英文字符时.他们在不同的编码方式下会占领不同的内存: 1. ANSI 中文占领 2 个字节的内存空间 ...
- (2.4)Mysql之SQL基础——下载与使用测试库
(2.4)SQL基础——下载与使用测试库 1.查看与下载测试数据库 2.查看安装向导视图 3.安装 [1]安装:解压后用 mysql 命令安装(记得加上set autocommit=1) [2]核验: ...
- spring MVC 学习(四)---拦截器,视图解析器
1.接口HandlerInterceptor 该接口包含3个方法,分别是preHandle,postHandle,afterCompletion,分别代表着执行前,执行后,执行完成要执行的方法,其中p ...