Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7203    Accepted Submission(s): 2752

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

水平序的Andrew算法:

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct node
{
double x,y;
}a[105],b[105]; double cmp(node n,node m) //先比較X坐标,在比較Y坐标(从小到大)
{
if(n.x != m.x)
return n.x < m.x;
else
return n.y < m.y;
} double Cross(node a,node b,node c) //计算叉积大小
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} double dis(node a,node b) //计算距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int CH(node* a,int n,node* b)
{
sort(a,a+n,cmp);
int m=0,i;
for(i=0;i<n;i++) //从左往右,选下边界
{
while(m > 1 && Cross(b[m-2],b[m-1],a[i]) < 0)
m--;
b[m++]=a[i];
} int k=m;
for(i=n-2;i>=0;i--) //从右往左,选上边界
{
while(m > k && Cross(b[m-2],b[m-1],a[i]) < 0)
m--;
b[m++]=a[i];
} if(n >1) m--;
return m;
} int main()
{
int n;
while(cin>>n)
{
if(n==0) break;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b)); int i,j;
for(i=0;i<n;i++)
{
cin>>a[i].x>>a[i].y;
} // cout<<CH(a,n,b)<<endl; //输出所选点的总数
if(n==1)
cout<<0.00<<endl;
else if(n==2)
printf("%.2lf\n",dis(a[0],a[1]));
else
{
int m=CH(a,n,b);
double s=0;
for(i=1;i<m;i++)
s+=dis(b[i-1],b[i]);
s+=dis(b[0],b[m-1]);
printf("%.2lf\n",s);
}
// for(i=0;i<CH(a,n,b);i++) //输出所选点的坐标
// cout<<b[i].x<<" "<<b[i].y<<endl; } return 0;
}

HDUJ 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 凸包模板

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

  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 (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

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

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

  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 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...

随机推荐

  1. python不可以打印.doc文件

    [背景] 需求: 打印word文件 模块: python-docx [问题] 传递xxx.doc文件给python脚本,执行后,控制台没有内容输出 经查询后了解到,大致理由: doc是早一代的word ...

  2. C/C++——[04] 语句

    在 C/C++语言中,语句以“ :”结束.某些情况下,一组语句在一起共同完成某一特定的功能,可以将它们用大括号括起来.我们称之为语句组.语句组可以出现在任何单个语句出现的地方. 1. 分支语句 一般情 ...

  3. [ python ] 初始面向对象

    首先,通过之前学习的函数编写一个 人狗大战 的例子. 分析下这个需求,人 狗 大战  三个事情.角色:人.狗动作:狗咬人,人打狗 先创建人和狗两个角色: def person(name, hp, ag ...

  4. acm专题---最小生成树

    kruscal(eloge): 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Problem Description There are N ...

  5. U3D的一些常用基础脚本

    修改渲染颜色和贴图 1: var texture :Texture ; 2:  3: function Start () { 4: renderer.material.mainTexture = te ...

  6. 使用情况查询top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. top - 01:06:48 up 1:22, 1 ...

  7. HTML表格的基本操作

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  8. ISSCC 2017论文导读 Session 14:A 288μW Programmable Deep-Learning Processor with 270KB On-Chip Weight

    A 288μW Programmable Deep-Learning Processor with 270KB On-Chip Weight Storage Using Non-Uniform Mem ...

  9. linux shell 正则表达式(BREs,EREs,PREs)的比较

    原文 :   linux shell 正则表达式(BREs,EREs,PREs)差异比较 在使用 linux shell的实用程序,如awk,grep,sed等,正则表达式必不可少,他们的区别是什么 ...

  10. WPF 获取指定文件的Icon

    C# var icon = System.Drawing.Icon.ExtractAssociatedIcon(@"filepath"); var m = new MemorySt ...