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 ...
随机推荐
- UEFI,BIOS,MBR,
UEFI启动是一种新的主板引导项,正被看做是有近20多年历史的BIOS 的继任者.顾名思义,快速启动是可以提高开机后操作系统的启动速度.由于开机过程中UEFI的介入 第一:安全性更强 UEFI启动需要 ...
- 前端开发 - JQuery - 上
一.js的缺点 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- D. Two Paths---cf14D(树的直径)
题目链接:http://codeforces.com/problemset/problem/14/D 题意:有n个city ; n-1条路:求断开一条路之后分成的两部分所构成的树的直径的积最大是多少: ...
- web前端 微信支付之H5支付
一.什么是微信H5支付? 微信,简直是21世纪的社交产品之最.人们的生活已经离不开它,因为它的触角广泛蔓延像一张巨大无形的网,从而让我们的生活更加便捷高效,这款社交工具我们不做过多评价,但是我们要通过 ...
- 调试maven源代码
下载源代码,导入idea 运行MavenCli ,设置vm参数 -Dclassworlds.conf=/Users/fsq/Downloads/apache-maven-3.6.2.0/bin/m2. ...
- 浅谈pipreqs组件(自动生成需要导入的模块信息)
简介 pipreqs的作用 一起开发项目的时候总是要搭建环境和部署环境的,这个时候必须得有个python第三方包的list,一般都叫做requirements.txt. 如果一个项目使用时virtua ...
- Linux基础配置
1 常用软件安装 yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop ...
- 011-HQL中级1-Hive快捷查询:不启用Mapreduce job启用Fetch task三种方式介绍
如果你想查询某个表的某一列,Hive默认是会启用MapReduce Job来完成这个任务,如下: hive; Total MapReduce jobs Launching Job out since ...
- Matlab GUI memo
有一段时间没写博客,一周4篇文章都坚持不下来,不知道写哪个方面的内容,写研究相关就怕论文查重查到,其他方面也没太多时间去学.还是花时间多学点其他方面.废话到此,很早就做过matlab gui相关,现在 ...
- Java Code Template
设置注释模板的入口:Window->Preference->Java->Code Style->Code Template 然后展开Comments节点就是所有需设置注释的元素 ...