Surround the Trees

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

Total Submission(s): 7164    Accepted Submission(s): 2738

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

题意是求将全部点围住的那个面积的最小周长。。可是要注意当仅仅有一个点时,也就输出0.00,当仅仅有两个点时。

。也就是两点间的距离。

这是凸包问题的入门题。。。(Orz)   用的是刘汝佳大白上的Andrew算法。。看他的代码实现。。简直丧心病狂。

Orz  。

。搞了好久的时间。。智商全然不够用。。

好吧。。由于是今天刚刚接触。

。所以一天也就弄了这么一道题。

。5555555.。

。泪流满面。。。

</pre><pre name="code" class="cpp">

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++) struct Point
{
double x, y;
}; void sort(Point *p, int n) //依照x从小到大排序(假设x同样, 依照y从小到大排序)
{
Point temp;
int i, j;
for(i=0; i<n-1; i++)
for(j=0; j<n-1-i; j++)
{
if(p[j].x>p[j+1].x)
{
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
if(p[j].x==p[j+1].x && p[j].y>p[j+1].y)
{
temp = p[j];
p[j] = p[j+1];
p[j+1] = temp;
}
}
} int cross(int x1, int y1, int x2, int y2) //看P[i]是否是在其内部。。
{
if(x1*y2-x2*y1<=0) //叉积小于0。说明p[i]在当前前进方向的右边。因此须要从凸包中删除c[m-1],c[m-2]
return 0;
else
return 1;
} int convexhull(Point *p, Point *c, int n)
{
int i,m=0,k;
f1(i, n) //下凸包
{
while(m>1 && !cross(c[m-2].x-c[m-1].x,c[m-2].y-c[m-1].y,c[m-1].x-p[i].x,c[m-1].y-p[i].y))
m--;
c[m++]=p[i];
}
k=m;
for(i=n-2; i>=0; i--) //求上凸包
{
while(m>k && !cross(c[m-2].x-c[m-1].x,c[m-2].y-c[m-1].y,c[m-1].x-p[i].x,c[m-1].y-p[i].y))
m--;
c[m++]=p[i];
}
if(n>1)
m--;
return m;
} double dis(Point a, Point b) //求两个凸包点之间的长度。。
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int main()
{
Point a[105], p[105];
int n, i, m;
double lenth;
while(scanf("%d",&n) &&n)
{
f1(i, n)
scanf("%lf %lf",&a[i].x, &a[i].y); if(n==1)
{
printf("0.00\n");
continue;
}
else if(n==2)
{
printf("%.2lf\n", dis(a[0], a[1]));
continue;
}
sort(a, n);
m=convexhull(a, p, n);
lenth = 0;
f2(i, m)
lenth+=dis(p[i],p[i-1]);
printf("%.2lf\n",lenth);
}
return 0;
}

HDU1392:Surround the Trees(凸包问题)的更多相关文章

  1. HDU-1392 Surround the Trees,凸包入门!

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

  2. hdu1392 Surround the Trees 凸包

    第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...

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

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

  6. hdu 1392 Surround the Trees 凸包裸题

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

  7. HDUJ 1392 Surround the Trees 凸包

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

  8. ACM学习历程—HDU1392 Surround the Trees(计算几何)

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

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

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

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

随机推荐

  1. 在kafka/config/目录下面有3个配置文件参数说明(producer.properties。consumer.properties。server.properties)

    (1).producer.properties:生产端的配置文件 #指定kafka节点列表,用于获取metadata,不必全部指定 #需要kafka的服务器地址,来获取每一个topic的分片数等元数据 ...

  2. BZOJ 1572 贪心(priority_queue)

    思路: 维护两个堆 一个按时间 (从后到前)的 另一个是按价值(从大到小)的 从时间的堆向价值的堆倒 每回(合法状态下)取当前的堆顶 判一判 //By SiriusRen #include <q ...

  3. 一台服务器安装运行多个Tomcat及注册服务

    项目需要,自己配置了一下,顺便分享出来. 1.下载对应版本Tomcat,这里下载Tomcat7.0.65.zip; 下载地址:http://archive.apache.org/dist/tomcat ...

  4. netty实现TCP长连接

    所用jar包 netty-all-4.1.30.Final.jar 密码:rzwe NettyConfig.java,存放连接的客户端 import io.netty.channel.group.Ch ...

  5. inode与ln命令

    inode可以看: http://www.cnblogs.com/itech/archive/2012/05/15/2502284.html 每个inode节点的大小,一般是128字节或256字节.i ...

  6. 将bat批处理命令文件固定到任务栏

    将bat批处理命令文件固定到任务栏第一种方法:使用链接工具http://www.xstui.com/read/3451.在任务栏点击右键,移动到工具栏,勾选链接工具2.你会在通知栏左侧看到链接字样,将 ...

  7. IntelliJ IDEA 2018 Community(社区版)创建J2EE项目+Tomcat9部署

    博主打算开始系统地自学JAVA,首要问题就是解决IDE的问题, 以前用过像VS.Android Studio.Eclipse,知道Eclipse是JAVA最传统的IDE, 用过VS和AS的朋友都知道, ...

  8. ZZUACM 2015 暑假集训 round 01

    A. Encoding Problem Description Given a string containing only 'A' - 'Z', we could encode it using t ...

  9. activity-栈相关属性

    1.启动任务栈 第一种,动作设置为“android.intent.action.MAIN”,类别设置为“android.intent.category.LAUNCHER”,可以使这个ACT(activ ...

  10. Android学习笔记之Bitmap位图虽触摸点移动

    package xiaosi.bitmap; import android.app.Activity; import android.os.Bundle; public class mianActiv ...