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

    题目传送门 题目大意:给定一棵K叉树,一个节点下的K个节点的分数为i,求包含大于等于D的边的总分数为N的方案总数,mod 1e9+7. 这是一道很好的树形DP题,首先看N和K两个条件,可以轻易的得到方 ...

  2. 成都Uber优步司机奖励政策(3月26日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. CF 600 E. Lomsat gelral

    E. Lomsat gelral http://codeforces.com/contest/600/problem/E 题意: 求每个子树内出现次数最多的颜色(如果最多的颜色出现次数相同,将颜色编号 ...

  4. struts2-01:作用域传值

    方式一.使用ServletActionContext(耦合度高,不建议使用) public String login(){ ServletActionContext.getRequest().getS ...

  5. C#如何使用反射实现通过字符串创建类

    在做项目中碰到一个问题,就是如何在知道一个类的名字,如何创建这个类呢.做的一个小测试,直接贴代码了. using System; using System.Collections.Generic; u ...

  6. 限时购校验小工具&dubbo异步调用实现限

    本文来自网易云社区 作者:张伟 背景 限时购是网易考拉目前比较常用的促销形式,但是前期创建一个限时购活动时需要各个BU按照指定的Excel格式进行选品提报,为了保证提报数据准确,运营需要人肉校验很多信 ...

  7. 2019年猪年海报PSD模板-第六部分

    14套精美猪年海报,免费猪年海报,下载地址:百度网盘,https://pan.baidu.com/s/1WdlIiIdj1VVWxI4je0ebKw            

  8. RSA加密通信小结(一)

    一.背景描述 帮朋友完成相关方案的改进. 二.计划与方案 1.加密方式采用RSA 1024加密. 2.发送与接收都采用RSA加密,采用两套不同的密钥. 3.统一的加解码函数.(此处除了对于传输数据进行 ...

  9. requests,lxml爬启信宝

    首先, 添加requests模块: 然后, 添加lxml模块: 启信宝登录抓包: QiXinBao.py: import requestsfrom lxml import etree loginUrl ...

  10. [JSON].remove( keyPath )

    语法:[JSON].remove( keyPath ) 返回:无 说明:移除指定路径的键 示例: Set jsonObj = toJson("{div:{'#text-1': 'is tex ...