HDU1392:Surround the Trees(凸包问题)
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
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.
is less than 32767. Each pair is separated by blank.
Zero at line for number of trees terminates the input for your program.
9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
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(凸包问题)的更多相关文章
- HDU-1392 Surround the Trees,凸包入门!
Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...
- hdu1392 Surround the Trees 凸包
第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu 1392 Surround the Trees (凸包)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDUJ 1392 Surround the Trees 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 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 ...
- 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 ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- 2011年度十大杰出IT博客获奖感言
2011年度十大杰出IT博客获奖感言 在各位评委.网友的支持下,我的博客从前50名中脱颖而出跻身10强,得到这个消息之后心中充满了喜悦.在这里要感谢51CTO为大家提供这样一个良好的展示平台. ...
- Kinect 开发 —— 常见手势识别(上)
悬浮按钮 (Hover Button) 悬浮按钮通过将鼠标点击换成悬浮然后等待(hover-and-wait)动作,解决了不小心点击的问题.当光标位于按钮之上时,意味着用户通过将光标悬浮在按钮上一段时 ...
- Spark 1.6.1 源码分析
由于gitbook网速不好,所以复制自https://zx150842.gitbooks.io/spark-1-6-1-source-code/content/,非原创,纯属搬运工,若作者要求,可删除 ...
- Javascript和jquery事件--事件冒泡和事件捕获
jQuery 是一个 JavaScript 库,jQuery 极大地简化了 JavaScript 编程,在有关jq的描述中,jq是兼容现有的主流浏览器,比如谷歌.火狐,safari等(当然是指较新的版 ...
- Python3.7&Django1.11.15 兼容性问题
环境: 1. Windows10 2. python3.7 3. Django1.11.15 启动Django时抛出以下异常: Unhandled exception in thread starte ...
- AsyncTask源代码翻译
前言: /** <p>AsyncTask enables proper and easy use of the UI thread. This class allows to perfor ...
- eclipse个人插件
1.SVN eclipse markets 安装m2e-subversion.svnkit 2.maven 本地装好mvn prefences导入maven安装目录和配置 3.单元测试覆盖率 EclE ...
- 洛谷P3273 [SCOI2011]棘手的操作
题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作:U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权 ...
- 含有过滤功能的android流式布局
FilterFlowLayout 含有过滤功能的流式布局, 參考FlowLayout 能够去除宽度不在范围(比例或真实值)内的子view 能够设置最大行数 能够加入组件间水平间距 能够加入行间距 系统 ...
- js遍历对象的属性和方法
js遍历对象的属性和方法 一.总结 二.实例 练习1:具有默认值的构造函数 实例描述: 有时候在创建对象时候,我们希望某些属性具有默认值 案例思路: 在构造函数中判断参数值是否为undefined,如 ...