分析:直接求出凸包。再算边长就可以。

另外仅仅有一个点时为0.00单独处理,两个点直接为距离也单独处理。

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; struct Point
{
Point(){}
Point(double _x,double _y):x(_x),y(_y){}
Point operator-(const Point& a) const
{
return Point(x-a.x,y-a.y);
}
double x,y;
}; double dis(const Point& a,const Point& b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double cross(const Point& a,const Point& b)
{
return a.x*b.y-a.y*b.x;
} bool cmp(const Point& a,const Point& b)
{
if(a.x!=b.x)
return a.x<b.x;
else
return a.y<b.y;
} int convexhull(Point* p,int n,Point* ch)
{
int i,m,k; sort(p,p+n,cmp);
m=0;
for(i=0;i<n;i++) //上凸包
{
while(m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
k=m;
for(i=n-2;i>=0;i--) //下凸包
{
while(m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
if(n>1) m--;
return m;
} int main()
{
Point a[105],p[105];
int n,i,m;
double ans; while(scanf("%d",&n)==1 &&n)
{
for(i=0;i<n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
if(n==1)
printf("0.00\n");
else if(n==2)
{
printf("%.2lf\n",dis(a[0],a[1]));
}
else
{
m=convexhull(a,n,p);
ans=0;
for(i=1;i<=m;i++)
ans+=dis(p[i],p[i-1]);
printf("%.2lf\n",ans);
}
}
return 0;
}

HDU ACM 1392 Surround the Trees-&gt;凸包的更多相关文章

  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(凸包入门)

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

  3. HDU 1392 Surround the Trees(凸包)

    题面 懒得粘贴了... 大致题意:坐标系内有若干个点,问把这些点都圈起来的最小凸包周长. 题解 直接求出凸包,统计一遍答案即可 #include<iostream> #include< ...

  4. HDU 1392 Surround the Trees(凸包)题解

    题意:给一堆二维的点,问你最少用多少距离能把这些点都围起来 思路: 凸包: 我们先找到所有点中最左下角的点p1,这个点绝对在凸包上.接下来对剩余点按照相对p1的角度升序排序,角度一样按距离升序排序.因 ...

  5. HDU 1392 Surround the Trees 构造凸包

    又是一道模板题 #include <iostream> #include <cstring> #include <cstdlib> #include <cst ...

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

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

  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(计算几何,求凸包周长)

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

  9. hdu 1392 Surround the Trees (凸包)

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

随机推荐

  1. Cordova 设置全屏及退出全屏切换

    设置全屏在super.init();之前 最后才退出全屏. 以下为具体代码: package com.agile.ittm; import android.os.Bundle; import andr ...

  2. Java 声明和访问控制(二) this关键字的访问

    this可以引用本类的静态变量和实例变量,而在静态方法中不能引用实例变量(因为当静态方法加载时,实例变量还没有被定义和初始化) this不可以引用局部变量.例如方法的参数变量,以及在方法中定义的局部变 ...

  3. JS判断浏览器是否支持某一个CSS3属性

    1.引子 css3的出现让浏览器的表现更加的丰富多彩,表现冲击最大的就是动画了,在日常书写动画的时候,很有必要去事先判断浏览器是否支持,尤其是在写CSS3动画库的时候.比如transition的ani ...

  4. 通过 Azure 媒体服务进行高速编码

    Milan Gada Azure 媒体服务首席项目经理  关于 Azure 媒体服务,客户问的最多的一个问题是能否进行高速编码.这个问题现在已经有了肯定的答案,目前有三种不同类型的 Encodin ...

  5. 向SharePoint页面添加后台代码

    转:http://www.cnblogs.com/chenzehe/archive/2009/12/25/1631863.html 在本文中,我将跟大家一起讨论,为MOSS的页面添加服务器端代码的另一 ...

  6. eclipse 常用快捷键整理

    1.整理代码的快捷键ctrl+shift + F 2.跳转代码行ctrl+L 3.可以列出所有快捷键  Ctrl+Shift+L

  7. Intersoft Mobile Studio 2013 R1 SP1 Crack

    Intersoft Mobile Studio 2013 R1 SP1 (iOS, Android & WinR) Leave a comment   tweet       inShare ...

  8. .NET+Oracle 分页

    http://www.cnblogs.com/Jusoc/archive/2011/08/28/2156530.html#commentform .在oracle的sqlplus或其他工具中运行一下p ...

  9. Ubuntu配置Android编译环境

    1.Ubuntu安装 VMware安装ubuntu之后,安装Vmware tools: 1.安装完ubuntu后,VMware Workstation菜单:虚拟机-->安装 Vmware Too ...

  10. objective-c中点语法的使用

    点语法的作用:提供一种访问属性的setter和getter的机制. 用法举例: 1.创建一个Person类,并声明属性.在person.h中. 2.实现一个init方法,并使用点语法等.在pers.m ...