Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10345    Accepted Submission(s): 4009

Problem Description
There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.

There are no more than 100 trees.

 
Input
The input contains one or more data sets. At first line of each input data set is number of trees in this data set, it is followed by series of coordinates of the trees. Each coordinate is a positive integer pair, and each integer is less than 32767. Each pair is separated by blank.

Zero at line for number of trees terminates the input for your program.

 
Output
The minimal length of the rope. The precision should be 10^-2.
 
Sample Input
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
 
Sample Output
243.06
 
Source
 
题意:n个点 求凸包的周长
题解:凸包模板题
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
};
typedef point vec;
vec operator -(point a,point b)
{
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b)
{
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t)
{
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t)
{
return vec(a.x/t,a.y/t);
}
int dcmp(double x)
{
if(fabs(x)<=eps) return ;
return x<?-:;
}
double cross(vec a,vec b) ///叉积
{
return a.x*b.y-a.y*b.x;
}
bool cmp(point a,point b)
{
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
double disn(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
/*两点之间的距离*/
}
void convexhull(point *s,int &n)
{
sort(s,s+n,cmp);
int m=;
point p[];
for(int i=; i<n; i++)
{
while(m> && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
int k=m;
for(int i=n-; i>=; i--)
{
while(m>k && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
m--;
n=m;
for(int i=; i<n; i++) s[i]=p[i];
/*建立凸包*/
}
int jishu;
int main()
{
while(scanf("%d",&jishu)!=EOF)
{
if(jishu==)
break;
point s[];
for(int i=; i<jishu; i++)
{
scanf("%lf %lf",&s[i].x,&s[i].y); }
if(jishu==)
{
printf("0.00\n");
continue;
}
if(jishu==)
{
printf("%.2f\n",disn(s[],s[]));
continue;
}
convexhull(s,jishu);
double sum=;
for(int i=; i<jishu-; i++)
{
sum+=disn(s[i],s[i+]);
}
sum+=disn(s[jishu-],s[]);
printf("%.2f\n",sum);
}
return ;
}

HDU 1392 凸包的更多相关文章

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

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

  2. hdu 1392凸包周长

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

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

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

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

  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:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

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

  8. HDU 4946 凸包

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

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

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

随机推荐

  1. S1:变量

    接触JS一段时间了,但总感觉不得要领,技术得不到提升,翻来覆去,决定对基础知识做一次系统的整理,要坚持每一天都有新的收获 ! 变量,即通过一个名字将一个值关联起来,以后通过变量就可以引用到该值,比如: ...

  2. 在Win7下安装IIS

    由于工作上的需要,有朋友在问在windows7系统下如何来配置IIS,大部分用户平时都很少接触到这个功能,所以对于安装配置十分陌生也是在所难免的,下面就让小编与你分享下windows7系统下IIS详细 ...

  3. ASP.NET MVC学习之路由篇(3)

    根据路由输出链接 既然是网站开发自然少不了链接,我们已经学会了强大的路由,但是还缺少一步就是能够将这些路由的路径输出到页面,下面我们就开始学习如何输出路由路径. 首先我们的路由注册部分如下所示: 1 ...

  4. $geoNear

    怎么使用mongoose的geoNear 2014-11-26 15:05:20|  分类: mongodb |  标签:mongoose  |举报|字号 订阅     下载LOFTER我的照片书   ...

  5. POJ 2559 Program C

    Submit Status Practice POJ 2559 Description A histogram is a polygon composed of a sequence of recta ...

  6. matlab 2012 vs2010混合编程

    电脑配置: 操作系统:window 8.1 Matlab 2012a安装路径:D:\Program Files\MATLAB\R2012a VS2010 : OpenCV 2.4.3:D:\Progr ...

  7. IntelliJ IDEA 12.0

    User name:JavaDeveloper Serial number:92547-KY2BB-QZ0S1-PEZCV-HUT8Q-6RYY4

  8. python tuple 操作

    特点:不可改(与字符串一样.不允许删除和修改) 操作:1.print 可使用跟%的元祖  print( '%s is %d years old' % (name, age)) 2.像列表一样有索引 3 ...

  9. iframe和form表单的target应用简单例子

    iframe和form表单的target属性   Problem: 刷新主页面中的其中一个iframe,其他内容不变 Solution: main.jsp <body onload=" ...

  10. declare 关键字在Oracle中的应用。

    一般用在trigger或匿名存储过程中使用.如 declare a number;begina:=1;end;