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 旋转卡壳 凸包的更多相关文章

  1. 【旋转卡壳+凸包】BZOJ1185:[HNOI2007]最小矩形覆盖

    1185: [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1945  Solve ...

  2. Gym 101606B - Breaking Biscuits - [凸包+旋转卡壳][凸包的宽度]

    题目链接:https://codeforces.com/gym/101606/problem/B 题解: 对于给出的 $n$ 个点,先求这些点的凸包,然后用旋转卡壳求出凸包的宽度(Width (min ...

  3. POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳

    题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...

  4. 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳

    因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...

  5. 【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)

    给定点集的最远两点的距离. 先用graham求凸包.旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径. ps:旋转卡壳算法的典型运用 http://blog.csdn.net/hanch ...

  6. 【BZOJ-1069】最大土地面积 计算几何 + 凸包 + 旋转卡壳

    1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2707  Solved: 1053[Submit][Sta ...

  7. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  8. 【BZOJ】1069: [SCOI2007]最大土地面积(凸包+旋转卡壳)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1069 显然这四个点在凸包上,然后枚举两个点找上下最大的三角形即可. 找三角形表示只想到三分QAQ.. ...

  9. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

随机推荐

  1. 解决Eclipse左键无法查看maven第三方包的源代码,多图亲测可用【转】

    Debug进不了的原因及解决办法: 一.ctrl+左键点击没有找到你的源码 1.先设置maven 2.通过maven下Jar包源码 选中总包目录下的pom.xml-->右键-->Run A ...

  2. TTrayIcon用法

    TTrayIcon用法 self.trycn1.Icon:=Application.Icon; Self.trycn1.Hint:=self.Caption; self.trycn1.Visible: ...

  3. 2012 Multi-University #7

    最短路+拆点 A As long as Binbin loves Sangsang 题意:从1走到n,每次都是LOVE,问到n时路径是连续多个"LOVE"的最短距离.秀恩爱不想吐槽. 分析:在普通的最 ...

  4. language level in Intellij IDEA

    The Language level setting sets which features the code assistance in the editor should support. For ...

  5. [转]Travis Ci的最接底气的中文使用教程

    相信大家对Travis Ci已经不再陌生了,Github上已经有大部分的项目已经采用了它. Travis Ci是一个基于晕的持续集成项目,目前已经支持大部分主流语言了,如:C.PHP.Ruby.Pyt ...

  6. JS:事件对象1

    一,this关键字和上下文 var box = document.getElementById("box");. 普通的函数如果没有给他传递参数,函数本身是没有参数的. test( ...

  7. Repeater用法

    Repeater用法: 使用Repeater可以绘制表头.表内.表尾比较复杂的表格,如以下实例: <asp:Repeater ID="Repeater1" runat=&qu ...

  8. 李洪强iOS经典面试题143-绘图与动画

    李洪强iOS经典面试题143-绘图与动画   绘图与动画 CAAnimation的层级结构 CAPropertyAnimation是CAAnimation的子类,也是个抽象类,要想创建动画对象,应该使 ...

  9. java并发编程(三)线程挂起,恢复和终止的正确方法

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17095733    下面我们给出不用上述两个方法来实现线程挂起和恢复的策略--设置标志位. ...

  10. 如何用最简单的方法将PCweb改成适合各种设备的web

    使web页面自适应设备大小 1)用一个<div>包围<body>的内容 2)该div属性的宽度设为100%   (宽度设为100%后,页面会随着设备窗口大小自动改变) 3)高度 ...