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

另外仅仅有一个点时为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. nutch http file 截断问题

    问题: 列表页预计抽取 355+6 但实际只抽取到220条链接. 原因是nutch对http下载的内容的长度进行了限制. 解决方案:这里将这个属性扩大10倍. vim conf/nutch-defal ...

  2. SQL 各种连接:内连接,外连接(左外,右外,完全外)

    在讲述之前,假设有如下两个表EMP, DEPT, 并且他们数据如下:

  3. 【Ecmall】ECMall2.x模板制作入门系列(认识ECMall模板)

    ECMall2.x模板制作入门系列之1(认识ECMall模板) 从ECMall2.0全新架构发布以来,随着版本的不断更新,ECMall已经逐渐走向一个稳定时期,是时候整理一些实用教程了.下面给大家带来 ...

  4. 发现一个Doxygen风格的QT帮助

    http://cep.xray.aps.anl.gov/software/qt4-x11-4.8.6-browser/classes.html http://cep.xray.aps.anl.gov/ ...

  5. 【踩坑记】从HybridApp到ReactNative

    前言 随着移动互联网的兴起,Webapp开始大行其道.大概在15年下半年的时候我接触到了HybridApp.因为当时还没毕业嘛,所以并不清楚自己未来的方向,所以就投入了HybridApp的怀抱. Hy ...

  6. Codevs_1040_[NOIP2001]_统计单词个数_(划分型动态规划)

    描述 http://codevs.cn/problem/1040/ 与Codevs_1017_乘积最大很像,都是划分型dp. 给出一个字符串和几个单词,要求将字符串划分成k段,在每一段中求共有多少单词 ...

  7. Makefile第四讲:include 引用其它makefile文件

    main.cpp #include "classes/fun.h" int main() { Test::display("Hello makefile"); ...

  8. Java Web SSH框架总是无法写入无法读取Cookie

    不关乎技术,关乎一个小Tips: 默认情况下,IE和Chrome内核的浏览器会认为http://localhost为无效的域名,所以不会保存它的cookie,使用http://127.0.0.1访问程 ...

  9. glsl-UBO

    UBO 是什么?为何要用UBO? 1.数据共享设计 采用Block的原因是: 如果你的程序中包含了多个着色器,而且这些着色器使用了相同的Uniform变量,你就不得不为每个着色器分别管理这些变量.Un ...

  10. poj 1265 Area(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description ...