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 ...
随机推荐
- 160518、java中使用百度地图(超级简单)
第一步:导入如下内容,红色的部分需要申请(个人通过手机号就可以申请) <script type="text/javascript" src="http://api. ...
- bootloader,kernel,initrc
http://www.ibm.com/developerworks/cn/linux/l-k26initrd/index.html http://www.68idc.cn/help/server/li ...
- SpringBoot与消息(RabbitMQ)
1. JMS和AMQP JMS(Java Message Service): ActiveMQ是JMS实现; AMQP(Advanced Message Queuing Protocol) 兼容JMS ...
- java实现简单的数据库的增删查改,并布局交互界面
一.系统简介 1.1.简介 本系统提供了学生信息管理中常见的基本功能,主要包括管理员.管理员的主要功能有对学生信息进行增加.删除.修改.查找等操作,对信息进行管理,对信息进行修改.查找等操作 ...
- node.js---sails项目开发
http://sailsdoc.swift.ren/ 这里有 sails中文文档 node.js---sails项目开发(1)安装,启动sails node.js---sails项目开发(2)安装测试 ...
- js如何转义和反转义html特殊字符
“<”如何反转义为“<”,“>”如何反转义为“>”,下面就介绍如何用js来实现这种类似的操作. //HTML转义 function HTMLEncode(html) { var ...
- Spark2.0 特征提取、转换、选择之二:特征选择、文本处理,以中文自然语言处理(情感分类)为例
特征选择 RFormula RFormula是一个很方便,也很强大的Feature选择(自由组合的)工具. 输入string 进行独热编码(见下面例子country) 输入数值型转换为double(见 ...
- Uboot命令U_BOOT_CMD
转载:http://blog.csdn.net/shengzhadon/article/details/52766263 U_BOOT_CMD是一个宏定义,具体功能是定义一个struct cmd_tb ...
- Linux系统常用命令汇总
命令格式:命令 -选项 参数,例如:ls -la /usr:当有多个选项时,可以写在一起.ifconfig:查看当前机器的IP信息service network restart:重启网络服务servi ...
- mysqldump 参数
mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等.对于导出的文件,可使用SOURCE命 ...