1393: Robert Hood 旋转卡壳 凸包
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393
http://poj.org/problem?id=2187 Beauty Contest
1393: Robert Hood
Description

Input

Output

Sample Input
5
-4 1
-100 0
0 4
2 -3
2 300
Sample Output
316.86590223
HINT

Source
分析:
给你 N 个点, 求所有点中最远两点距离。即是凸包直径。
AC代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn = +;
int n,m; struct Point{
double x,y;
Point(){};
Point(double _x, double _y)
{
x = _x;
y = _y;
} Point operator - (const Point & B) const
{
return Point(x-B.x, y-B.y);
}
}p[maxn], ch[maxn]; bool cmp(Point p1, Point p2)
{
if(p1.x == p2.x) return p1.y < p2.y;
return p1.x < p2.x;
} int squarDist(Point A, Point B) /**距离的平方*/
{
return (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y);
} double Cross(Point A, Point B) /**叉积*/
{
return A.x*B.y-A.y*B.x;
} void ConvexHull() /** 基于水平的Andrew算法求凸包 */
{
sort(p,p+n,cmp); /**先按照 x 从小到大排序, 再按照 y 从小到大排序*/
m = ; for(int i = ; i < n; i++) /** 从前往后找 */
{
while(m > && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
int k = m;
for(int i = n-; i >= ; i--) /**从后往前找, 形成完整的封闭背包*/
{
while(m > k && Cross(ch[m-]-ch[m-], p[i]-ch[m-]) <= ) m--;
ch[m++] = p[i];
}
if(n > ) m--;
} int rotating_calipers() /**旋转卡壳模板*/
{
int q = ;
int ans = ;
ch[m] = ch[]; /**凸包边界处理*/
for(int i = ; i < m; i++) /**依次用叉积找出凸包每一条边对应的最高点*/
{
while(Cross(ch[i+]-ch[i], ch[q+]-ch[i]) > Cross(ch[i+]-ch[i], ch[q]-ch[i]))
q = (q+)%m;
ans = max(ans, max(squarDist(ch[i], ch[q]), squarDist(ch[i+], ch[q+])));
}
return ans;
} int main()
{
while(scanf("%d", &n) != EOF)
{
if(n == ) break;
for(int i = ; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y); ConvexHull(); printf("%.8lf\n", sqrt(rotating_calipers()));
}
return ;
}
同学用结构体 + 遍历凸包也可以解决。
AC代码:
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
struct point
{
int x;
int y;
}p[],res[];
int cmp(point p1,point p2)
{
return p1.y<p2.y||(p1.x==p2.x&&p1.x<p2.x);
}
bool ral(point p1,point p2,point p3)
{
return (p2.x-p1.x)*(p3.y-p1.y)>(p3.x-p1.x)*(p2.y-p1.y);
}
int main()
{
int n,i,j;
while((scanf("%d",&n))!=EOF)
{
for(i=;i<n;i++)
scanf("%d %d",&p[i].x,&p[i].y);
sort(p,p+n,cmp);
res[]=p[];
res[]=p[];
int top=;
for(i=;i<n;i++)
{
while(top&&!ral(res[top],res[top-],p[i]))
top--;
res[++top]=p[i];
}
int len=top;
res[++top]=p[n-];
for(i=n-;i>=;i--)
{
while(top!=len&&!ral(res[top],res[top-],p[i]))
top--;
res[++top]=p[i];
}
double maxx=;
for(i=;i<top;i++)
{
for(j=i+;j<top;j++)
{
double s=(res[i].x-res[j].x)*(res[i].x-res[j].x)+(res[i].y-res[j].y)*(res[i].y-res[j].y);
if(s>maxx)
maxx=s; }
}
printf("%.8lf\n",sqrt(maxx));
}
return ;
}
1393: Robert Hood 旋转卡壳 凸包的更多相关文章
- 【旋转卡壳+凸包】BZOJ1185:[HNOI2007]最小矩形覆盖
1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1945 Solve ...
- Gym 101606B - Breaking Biscuits - [凸包+旋转卡壳][凸包的宽度]
题目链接:https://codeforces.com/gym/101606/problem/B 题解: 对于给出的 $n$ 个点,先求这些点的凸包,然后用旋转卡壳求出凸包的宽度(Width (min ...
- POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳
题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- 【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)
给定点集的最远两点的距离. 先用graham求凸包.旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径. ps:旋转卡壳算法的典型运用 http://blog.csdn.net/hanch ...
- 【BZOJ-1069】最大土地面积 计算几何 + 凸包 + 旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2707 Solved: 1053[Submit][Sta ...
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- 【BZOJ】1069: [SCOI2007]最大土地面积(凸包+旋转卡壳)
http://www.lydsy.com/JudgeOnline/problem.php?id=1069 显然这四个点在凸包上,然后枚举两个点找上下最大的三角形即可. 找三角形表示只想到三分QAQ.. ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
随机推荐
- CodeForces 540
A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【原】iOS学习之应用程序的启动原理
最近看视频了解了一下应用程序的启动原理,这里就做一个博客和大家分享一下,相互讨论,如果有什么补充或不同的意见可以提出来! 1.程序入口 众所周知,一个应用程序的入口一般是一个 main 函数,iOS也 ...
- Jenkins + Ant + Git + Tomcat自动化部署
环境linux下,大致的配置内容如下: 首先安装JDK配置环境变量等. 其次安装ANT配置ANT_HONE并把bin目录加入PATH中. 然后安装Git,并生成sshkey配置ssh 安装tomcat ...
- 【贪心】SOJ 13983
SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...
- 立flag
lixintong这半年来一直浪啊浪啊都不认真做题!!!!!!简直是太堕落啦!!lixintong非常讨厌这样的lixintong !!! 鉴于lixintong NOIP 完全爆炸啦! lixint ...
- django 过滤器、日日期格式化参数
转载:http://blog.csdn.net/xyp84/article/details/7945094 django1.4 html页面从数据库中读出DateTimeField字段时,显示的时间格 ...
- 修改ie的默认值 为ie10
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE10" />
- BSBuDeJie_03
一 快速登录 1 改变状态栏的style - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightConte ...
- PostGr-SQL database创建表
postgres=# create database vertigo_sandbox; postgres=# \connect vertigo_sandbox vertigo_sandbox=# CR ...
- hive 使用where条件报错 java.lang.NoSuchMethodError: org.apache.hadoop.hive.ql.ppd.ExprWalkerInfo.getConvertedNode
hadoop 版本 2.6.0 hive版本 1.1.1 错误: java.lang.NoSuchMethodError: org.apache.hadoop.hive.ql.ppd.ExprWalk ...