传送门: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. 查询PO的预付款剩余金额

    FUNCTION zrfc_mm016. *"---------------------------------------------------------------------- * ...

  2. winform利用代码将控件置于顶端底端

    有时,我们可能动态的添加控件,并准备将其置于对顶层或最底层.实现的方法有两个: 一种方法是在WinForm窗体中使用Controls控件集的SetChildIndex方法,该方法将子控件设定为指定的索 ...

  3. 解决Charles Response 中文乱码

    Response中文乱码:在Info.plist 中 的vmoption 添加-Dfile.encoding=UTF-8 info.plist路径 应用程序->Charles.app->显 ...

  4. 推荐五个最好的MySQL GUI工具

    推荐五个最好的MySQL GUI工具 在本文中,我们会介绍一些最常用的MySQL GUI工具并附上下载链接.希望大家能更好的运用这些工具. AD:网+线下沙龙 | 移动APP模式创新:给你一个做APP ...

  5. Android Branch and master source code merge(patch)

    Environment : Android 4.4.2 merge with Android 4.4.3(with other vendors source code) 1.确定你要merge 到 其 ...

  6. fullcalendar日历控件知识点集合

    1.基本的语法: 首先,fullcalendar和JQUERY一样,以面向对象的方式来组织代码.当然,这里的面向对象不过指能够把整个fullcalendar理解为一个类,这个类里包含有非常多的属性.方 ...

  7. MSSQL - 存储过程Return返回值

    1.存储过程中不使用外部参数. 存储过程: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ========================== ...

  8. dephi中单击鼠标拖动窗口(使用WM_SYSCOMMAND)

    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Int ...

  9. 【书评】RHCSA/RHCE Red Hat Linux 认证学习指南(第6版)EX200 & EX300

    这次参加 CSDN 举办的读书活动,正赶上项目忙,看得也是断断续续,拖了2周了,才能来写这个书评. ========== 书评的分割线 ========== 首先,我会肯定的告诉你,不论你是一名专业的 ...

  10. TestNg JAVA 自动化单元测试框架Demo

    TestNg TestNg 是java的一个自动化单元测试框架 参考:http://testng.org/doc/index.html 环境准备 既然是java 的自动化单元测试框架,就必须要有jav ...