传送门:Surround the Trees

题意:求凸包的周长。

分析:凸包模板题,先按极角排好序后,然后根据叉积正负确定凸包。

#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std; const double eps = 1e-;
const int N = ;
int sgn(double x)
{
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
}
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);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
Point p[N];
int Stack[N],top;
bool cmp(Point p1,Point p2)
{
double tmp=(p1-p[])^(p2-p[]);
if(sgn(tmp)==)return sgn(dist(p[],p1)-dist(p[],p2))<=;
return sgn(tmp)>;
}
void Graham(int n)
{
sort(p+,p+n,cmp);
Stack[]=;
Stack[]=;
top=;
for(int i=;i<n;i++)
{
while(top>&&sgn((p[Stack[top-]]-p[Stack[top-]])^(p[i]-p[Stack[top-]]))<=)top--;
Stack[top++]=i;
}
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y<p[].y||p[i].y==p[].y&&p[i].x<p[].x)
swap(p[],p[i]);
}
if(n==)puts("0.00");
else if(n==)printf("%.2lf\n",dist(p[],p[]));
else
{
Graham(n);
double ans=;
for(int i=;i<top;i++)
ans+=dist(p[Stack[i]],p[Stack[(i+)%top]]);
printf("%.2lf\n",ans);
}
}
return ;
}

hdu 1392(凸包)的更多相关文章

  1. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  2. HDU 1392 凸包

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  3. hdu 1392凸包周长

    //用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...

  4. HDU - 1392 凸包求周长(模板题)【Andrew】

    <题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...

  5. Surround the Trees HDU 1392 凸包

    Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to surround a ...

  6. HDU 1392 Surround the Trees(凸包入门)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  8. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  9. HDU 4946 凸包

    给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...

  10. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

随机推荐

  1. 如何在VC中显示透明背景位图

    简单的调用系统API. Windows NT/2000/XP: Included in Windows 2000 and later.Windows 95/98/Me: Included in Win ...

  2. 使用ItextSharp产PDF完整操作

    原文 使用ItextSharp产PDF完整操作 记得上回有写到用C#操作Excel(.net 4.0) 很多朋友说推荐用NPOI,的确,用微软自带的操作execl会有很大的问题.客户的主机不愿意安装e ...

  3. Spring注入静态变量(转)

    今天碰到一个问题,我的一个工具类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class Util{ private static XXX xxx; xxx = ...

  4. SharePoint 2013 &quot;通知我&quot;简单的功能

    简单的功能 "通知我"内部列表或文档库中的主要项目.加入/删除/修改等操作,用户的E- mail通知设定功能:设置列表或文档库通知的能力,有可能设置通知为一个单一的项目.这是Sha ...

  5. Linux下mpi环境配置与执行步骤(Ubuntu为例)

    转载注明出处: http://blog.csdn.net/bendanban/article/details/9136755 以两台计算机为例,将这两台计算机应用于MPI运行环境. 第一步:在两台机器 ...

  6. js点击button按钮跳转到另一个新页面

    点击按钮怎么跳转到另外一个页面呢?我们在网站制作中可能是需要的,因为有时我们需要做这样的效果,尤其是将按钮做成一个图片,而点击图片要跳转到新的页面时,怎么做到呢? 这样的效果可以:onclick=&q ...

  7. BMP文件结构

    1. 位图文件头 位图文件头包含有关于文件类型.文件大小.存放位置等信息,在Windows 3.0以上版本的位图文件中用BITMAPFILEHEADER结构来定义: typedef struct ta ...

  8. QT---系统托盘图标不显示原因

    很久没用QT写UI相关的东西了,有些东西都忘记了,今天竟然忘记了系统托盘图标是怎么显示的了.下面说下解决方法 1.现象, 设置了QSystemTrayIcon的Icon图标,但就是不显示自己设置的图片 ...

  9. hbase memstorelab

    关于MemStore的补充 在通过HStore.add向store中加入�一个kv时,首先把数据写入到memstore中.这一点没有什么说明: publiclongadd(finalKeyValue ...

  10. access数据库:怎么直接从access里把数据里同样的文字替换成空字符&quot;&quot;

    access数据库:怎么直接从access里把数据里同样的文字替换成空字符"" 搜所到文字后,替换的项里写"",就是了.一定要是英文的""