Surround the Trees

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

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
 
Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:  2150 1147 1558 1374 2202 
 

凸包入门:

 //78MS    248K    1553 B    C++
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 105
struct node{
double x,y;
}p[N],stack[N];
double dist(node a,node b) //两点距离
{
return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
}
double crossprod(node a,node b,node c) //计算叉积
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int cmp(const void*a,const void*b) //按要求排序
{
node c=*(node*)a;
node d=*(node*)b;
double k=crossprod(p[],c,d);
if(k< || !k && dist(p[],c)>dist(p[],d))
return ;
return -;
}
double Graham(int n) //Graham扫描法
{
for(int i=;i<n;i++)
if(p[i].x<p[].x || p[i].x==p[].x && p[i].y<p[].y){
node temp=p[];
p[]=p[i];
p[i]=temp;
}
qsort(p+,n-,sizeof(p[]),cmp);
p[n]=p[];
for(int i=;i<;i++)
stack[i]=p[i];
int top=;
for(int i=;i<n;i++){
while(crossprod(stack[top-],stack[top],p[i])<= && top>=)
top--;
stack[++top]=p[i];
}
double ans=dist(stack[],stack[top]);
for(int i=;i<top;i++)
ans+=dist(stack[i],stack[i+]);
return ans;
}
int main(void)
{
int n;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
if(n==){
puts("0.00");continue;
}
if(n==){
printf("%.2lf\n",dist(p[],p[]));
continue;
}
printf("%.2lf\n",Graham(n));
}
return ;
}

hdu 1392 Surround the Trees (凸包)的更多相关文章

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

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

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

  3. hdu 1392 Surround the Trees 凸包模板

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

  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(凸包*计算几何)

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

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

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

随机推荐

  1. IOI 2017 Practice Contest mountains

    Mountains 题面 题意: 选最多的点使得两两看不见. 分析: 分治,solve(l,r)为区间[l,r]的答案.那么如果不选最高点,分治两边即可,选了最高点,那么在最高点看不见的区间里分治. ...

  2. Homebrew安装Redis找不到redis.conf文件

    使用Homebrew安装redis完成后,使用命令 redis-server 启动redis,如下图所示: 启动信息中存在一条警告信息:没有指定的配置文件 然而在安装目录中并没有发现redis.con ...

  3. xencenter迁移云主机方法

    问题:POOL中计算节点内存不足. 解决方法:1.为计算节点添加内存(费用高)2.将部分资源迁移到其它POOL中. 方法: 1.选择要迁移的虚拟机 2.选择保存路径 这里可以看到可以批量导出: 注意: ...

  4. 孤荷凌寒自学python第七十八天开始写Python的第一个爬虫8

    孤荷凌寒自学python第七十八天开始写Python的第一个爬虫8 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 到今天止基本完成了对docx模块针 ...

  5. spark相关脚本解析

    spark-shell/spark-submit/pyspark等关系如下: #spark-submit 逻辑: ########################################### ...

  6. 关于C#中如何使用wmi获得操作系统信息?

    最近项目中用到了windows server 2012操作系统中的存储池和ISCSI Disk的技术.前期,我们整个操作都是用power shell脚本去实现了.带来了不方便,后期要使用wmi API ...

  7. Python变量常量及注释

    一.变量命名规则1.有字母.数字.下划线搭配组合而成2.不能以数字开头,更不能全为数字3.不能用Python的关键字4.不要太长5.名字要有意义6.不要用中文7.区分大小写8.采用驼峰体命名(多个单词 ...

  8. 十二:NodeManager

    NM负责启动和管理节点上的containers.AM通过containers来运行任务. Health Checker Service 创建检查服务     NM运行一个检查服务来检查节点的状态,该服 ...

  9. 20172314 Android程序设计 实验四

    课程:<程序设计与数据结构> 班级: 1723 姓名: 方艺雯 学号:20172314 实验教师:王志强 实验日期:2018年5月30日 必修/选修: 必修 1.实验内容及要求 (1)An ...

  10. Calculation PartⅡ

    GitHub/object-oriented 误删内容--周末修复