POJ - 2187:Beauty Contest (最简单的旋转卡壳,求最远距离)
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
题意:给定二维平面上N个点,输出最远距离的平方。
思路:先求出凸包,只考虑凸包上的点。利用旋转卡壳求最远距离。模板达成。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define RC rotating_calipers
using namespace std;
const int maxn=;
struct point{
double x,y;
point(double x=,double y=):x(x),y(y){}
bool operator < (const point &c) const { return x<c.x||(x==c.x&&y<c.y);}
point operator - (const point &c) const { return point(x-c.x,y-c.y);}
double operator * (const point &c) const { return x*c.y-y*c.x; }
double operator | (const point &c) const { return (x-c.x)*(x-c.x)+(y-c.y)*(y-c.y); }
};
double det(point A,point B){ return A.x*B.y-A.y*B.x;}
double det(point O,point A,point B){ return det(A-O,B-O);}
point a[maxn],ch[maxn];
void convexhull(int n,int &top)
{
sort(a+,a+n+); top=;
for(int i=;i<=n;i++){
while(top>&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
int ttop=top;
for(int i=n-;i>=;i--){
while(top>ttop&&det(ch[top-],ch[top],a[i])<=) top--;
ch[++top]=a[i];
}
}
double rotating_calipers(point p[],int top)
{
double ans=; int now=;
rep(i,,top-){
while(det(p[i],p[i+],p[now])<det(p[i],p[i+],p[now+])){
now++; //最远距离对应了最大面积。
if(now==top) now=;
}
ans=max(ans,(p[now]|p[i]));
}
return ans;
}
int main()
{
int N; scanf("%d",&N);
for(int i=;i<=N;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
int top; convexhull(N,top);
printf("%lld",(ll)RC(ch,top));
return ;
}
POJ - 2187:Beauty Contest (最简单的旋转卡壳,求最远距离)的更多相关文章
- 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(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- 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 (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
随机推荐
- 0608pm单例模式and面向对象的六大原则
//把类控制住,不让外界造她的对象class DA{ public $name; static private $dx;//存放对象的变量 //将构造变为私有,外界没法造对象 private func ...
- 解决 flex align-items:center 无法居中(微信小程序)
因为最近再做小程序,需要用到flex布局,因为写惯了web项目,初次学习确实感弹性布局的强大(关键是不用再管可恶的ie了). 但是也遇到了align-items:center无法居中的问题,想了很久终 ...
- 每天一个Linux命令(59)wget命令
wget命令用来从指定的URL下载文件. (1)用法: 用法: wget [参数] [URL] (2)功能: 功能: wget命令用来从指定的URL下载 ...
- HAproxy 源码包安装
HAproxy 源码包安装 系统环境:Centos 7 x64位 服务版本:haproxy-1.7.8.tar.gz 编译工具:gcc 下载地址 HAproxy:https://pan.baidu.c ...
- FullPage.js全屏滚动插件
一.介绍 fullPage.js是一个基于jQuery的插件,他能够很方便.很轻松的制作出全屏网站,主要功能有: 1.支持鼠标滚动 2.多个回调函数 3.支持手机.平板触摸事件 4.支持CSS3动画 ...
- INSPIRED启示录 读书笔记 - 第27章 合理运用瀑布式开发方法
瀑布式开发方法的基本原则 1.采用阶段式开发:软件开发过程被事先分成固定的几个阶段,撰写书面的需求说明文档.设计高层软件架构.设计低层细节.编写代码.测试.部署 2.采用阶段式评审:每个阶段结束后,对 ...
- 关于在windows命令提示符cmd下运行Java程序的问题
1. win+R出现cmd运行窗口,输入Java源码文件名运行时,错误: 找不到或无法加载主类... 问题背景:我已经配置好了Java环境(安装路径PATH,JAVA_HOME已装好,cmd运行jav ...
- 4.JDBC编程
01.JDBC_Java程序和MySQL的关系: 1).Java程序跟其它MySQL客户端一样,就是一个"客户端",用于"封装SQL语句"并发送给MyS ...
- ElasticSearch入门常用命令
基于开源项目MyAlice智能客服学习ElasticSearch https://github.com/hpgary/MyAlice/wiki/%E7%AC%AC01%E7%AB%A0%E5%AE%8 ...
- nodejs mysql 操作数据库方法一详解
nodejs mysql 数据查询例子 时间 2014-11-11 15:28:01 姜糖水原文 http://www.cnphp6.com/archives/59864 1.安装nodejs 2 ...