题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1392

题意:给出一些点的坐标,求最小的凸多边形把所有点包围时此多边形的周长。

解法:凸包ConvexHull 模板题

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define inf 0x7fffffff
#define PI 3.141592654
#define exp 1e-10
using namespace std;
struct Point
{
double x,y;
Point (double x=,double y=):x(x),y(y){}
friend bool operator < (Point A,Point B)
{
if (A.x != B.x) return A.x < B.x;
return A.y<B.y;
}
}an[];
typedef Point Vector;
Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x , A.y+B.y); }
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x , A.y-B.y); } int dcmp(double x)
{
if (fabs(x)<exp) return ;
else return x< ? - : ;
}
double cross(Vector A,Vector B)
{
return A.x*B.y-B.x*A.y;
}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n);
int m=;
for (int i= ;i<n ;i++)
{
while (m> && dcmp(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 && dcmp(cross(ch[m-]-ch[m-] , p[i]-ch[m-]))<=) m--;
ch[m++]=p[i];
}
ch[m++]=ch[];
if (n>) m--;
return m;
}
double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
int n;
while (cin>>n,n)
{
for (int i= ;i<n ;i++)
scanf("%lf%lf",&an[i].x,&an[i].y);
if (n==) {printf("0.00\n");continue;}
else if (n==) {printf("%.2f\n",dis(an[],an[]));continue;}
Point bn[];
int m=ConvexHull(an,n,bn);
double sum=;
for (int i= ;i<m ;i++)
{
sum += dis(bn[i],bn[i+]);
}
printf("%.2f\n",sum);
}
return ;
}

hdu 1392 Surround the Trees的更多相关文章

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

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

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

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

  3. 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 ...

  4. hdu 1392 Surround the Trees 凸包裸题

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

  5. hdu 1392 Surround the Trees 凸包模板

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

  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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

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

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

  9. 计算几何(凸包模板):HDU 1392 Surround the Trees

    There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So a ...

随机推荐

  1. css3 文本效果

    CSS3 文本效果   1 CSS3 文本阴影在 CSS3 中,text-shadow 可向文本应用阴影,能够规定水平阴影.垂直阴影.模糊距离,以及阴影的颜色.text-shadow: 5px 5px ...

  2. Asp.net MVC4 Knockoutjs BootStrap Ace NinJect Jqgrid sqlserver2008

    Asp.net MVC4 Knockoutjs  BootStrap Ace NinJect  Jqgrid sqlserver2008

  3. 关于commons-fileupload组件上传文件中文名乱码问题

    java web开发,常用到的文件上传功能,常用的commons-fileupload和commons-io两个jar包.关于如何使用这两个jar来完成文件上传的功能,这里不做详解.使用commons ...

  4. 【php学习之路】php基础语法

    一.什么是php?       PHP即PHP: Hypertext Preprocessor(超文本处理器),是一种服务器端脚本语言,适用于创建web站点.开源免费 二.php能做什么?       ...

  5. PHP变量作用域以及地址引用问题

    作用域的概念: 在PHP脚本的任何位置都可以声明变量,但是,声明变量的位置会大大影响访问变量的范围.这个可以访问的范围称为作用域. 主要的常用的包括:局部变量.全局变量.静态变量. 1.局部变量:就是 ...

  6. 如何解决加载动态链接库DLL失败,返回0,GetLastError返回错误码126

    通常情况下使用LoadLibrary加载DLL都可以成功,但是当被加载的DLL内部依赖其他DLL无法被找到时,该函数会返回126(ERROR_MOD_NOT_FOUND)错误. 解决办法有2种: 1) ...

  7. JDBC基础一

    JDBC:java database connectivity SUN公司提供的一套操作数据库的标准规范. JDBC与数据库驱动的关系:接口与实现的关系. JDBC规范(掌握四个核心对象): Driv ...

  8. 获取月份对应的day

    function getDaysInMonth(month, year) { , , , , , , , , , , , ]; //主要处理二月份的天数 ) && (year % == ...

  9. 导购效果跟踪: SPM

    什么是SPM SPM是淘宝社区电商业务(xTao)为外部合作伙伴(外站)提供的一套跟踪引导成交效果数据的解决方案. 下面是一个跟踪点击到宝贝详情页的引导成交效果数据的SPM示例: http://det ...

  10. 一些关于python的小感想

    python是一门优秀的语言,但随之而来的是大量的知识,各种模块,相信一个人的大脑是很难记住如此多的内容.这时后的我们就应该想办法避免去记忆这么多的内容. 1.查看官方文档(英语很重要,啥也不说了) ...