凸包(hd1392)
Surround the Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8996 Accepted Submission(s):
3457
点我
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.
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.
10^-2.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
struct point
{
int x,y;
}list[];
int stack[];
int cross(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
double dis(point p1,point p2)
{
return sqrt(double(p2.x-p1.x)*(p2.x-p1.x)+double(p2.y-p1.y)*(p2.y-p1.y));
}
bool cmp(point p1,point p2)
{
int tem=cross(list[],p1,p2);
if(tem>)
return ;
else if(tem==&&dis(list[],p1)<dis(list[],p2))
return ;
else
return ;
}
void init(int n)
{
int i,k;
point p0;
cin>>list[].x>>list[].y;
for(i=;i<n;i++)
{
cin>>list[i].x>>list[i].y;
if(list[i].y<list[].y||(list[i].y==list[].y&&list[i].x<list[].x))
{
p0=list[];
list[]=list[i];
list[i]=p0;
}
}
sort(list+,list+n,cmp);
}
int main()
{
int i,n;
//freopen("in.txt","r",stdin);
while(cin>>n&&n)
{
memset(list,,sizeof(list));
memset(stack,,sizeof(stack));
if(n==)
cout<<0.00<<endl;
else if(n==)
{
cin>>list[].x>>list[].y>>list[].x>>list[].y;
printf("%0.2f\n",dis(list[],list[]));
}
else
{
stack[]=;
stack[]=;
int top=;
init(n);
for(i=;i<n;i++)
{
while(top>&&cross(list[stack[top]],list[stack[top-]],list[i])>)
top--;
top++;
stack[top]=i;
}
double sum=;
for(i=;i<=top;i++)
{
sum+=dis(list[stack[i]],list[stack[i-]]);
}
sum+=dis(list[],list[stack[top]]);
printf("%0.2f\n",sum);
}
}
}
凸包(hd1392)的更多相关文章
- HDU1392Surround the Trees(凸包判断 + 求周长)
http://www.cnblogs.com/hmhard/archive/2013/02/05/2893035.html 这是判断三角区域那块写的不好. 判断凸包的方法: 1.将所有点按照y从小到大 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- ZOJ 3871 Convex Hull(计算几何、凸包)
题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...
- UVALive 2453 Wall (凸包)
题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...
- UVA 11168 Airport(凸包+直线方程)
题意:给你n[1,10000]个点,求出一条直线,让所有的点都在都在直线的一侧并且到直线的距离总和最小,输出最小平均值(最小值除以点数) 题解:根据题意可以知道任意角度画一条直线(所有点都在一边),然 ...
- 关于2016.12.12——T1的反思:凸包的意义与应用
2016.12.12 T1 给n个圆,保证圆圆相离,求将圆围起来的最小周长.n<=100 就像上图.考场上,我就想用切线的角度来做凸包.以圆心x,y排序,像点凸包一样,不过用两圆之间的下切线角度 ...
- poj1228--稳定凸包
题目大意:给你一个凸包上的某些点(可能在凸包内),询问是否能确定这个凸包. 思路:先求出题目给出的点的凸包,看看在凸包的每条边内(不包括端点)有没有点,若有,则这条边是确定的,若没有,则这条边不确定, ...
- POJ 2225 / ZOJ 1438 / UVA 1438 Asteroids --三维凸包,求多面体重心
题意: 两个凸多面体,可以任意摆放,最多贴着,问他们重心的最短距离. 解法: 由于给出的是凸多面体,先构出两个三维凸包,再求其重心,求重心仿照求三角形重心的方式,然后再求两个多面体的重心到每个多面体的 ...
- HDU 4946 Area of Mushroom(构造凸包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 题目大意:在一个平面上有n个点p1,p2,p3,p4....pn,每个点可以以v的速度在平面上移 ...
随机推荐
- 使用BufferedReader的时候出现的问题
今天在使用BufferedReader的时候,出现了一个奇怪的问题 有时候换行的时候,行首会少一个字符 开始的代码是这样写的 while( br.read()!=-1 ){ String str = ...
- 开心学习系列学习笔记-----nodejs缺点
不支持故障恢复 不知你是否在调试的过程中注意,当程序有错误发生时,整个进程就会结束,需要重 新在终端中启动服务器.这一点在开发中无可厚非,但在产品环境下就是严重的问题 了,因为一旦用户访问时触 ...
- python 反向查找
python 字符串反向查找大部分在正向查找前面加入r eg: str.rfind('str') str.rsplit(',')
- BZOJ 2298 problem a(区间DP)
题意:一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) 思路:考虑最多有多少人说真,那么答案就是n-max. ai个人分数 ...
- IO-APIC
MP-BIOS bug :8254 timer not connected to IO-APIC解决办法 云计算中在基于一个template image instance vmServer时出现上述的 ...
- wifi_uplink脚本分析
~ >: vim apps/tools/wifi_uplink #!/bin/sh # Copyright (C) 2012 GuoWenxue <guowenxue@gmail.com ...
- 把Go程序变小的办法
把Go程序变小的办法是: go build -ldflags “-s -w” (go install类似) -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了, 这 ...
- cocoapods在OS X Yosemite系统中报错
之前使用cocoapods一直是正常使用的,刚换了电脑,使用pod install的时候报错: /System/Library/Frameworks/Ruby.framework/Versions/2 ...
- BOM 窗体相关属性以及页面可见区域的获取方式
1 在IE Safari Oper Chrome 都提供了screenLeft和screenTop属性: screenLeft : 相对于屏幕左边的距离 screenTop : 相对于屏幕上边的距离 ...
- Vim知识点收集
(注意: 只记录工作中实际使用的命令) 删除带有pattern的所有行 :g/pattern/d 删除不带pattern的所有行 :g!/pattern/d 匹配red和blue,无次序 ...