凸包(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的速度在平面上移 ...
随机推荐
- MHA环境搭建【3】node相关依赖的解决
mha的node软件包依赖于perl-DBD-Mysql 这个包,我之前有遇到过用yum安装perl-DBD-MySQL,安装完成后不能正常使用的情况,所以这里选择源码编译安装: perl5.10.1 ...
- HoG feature for human detection(HoG 行人识别)
本文大部分内容总结于其他文章 1.介绍 HOG(Histogram of Oriented Gradient)是2005年CVPR会议上,法国国家计算机科学及自动控制研究所的Dalal等人提出的一种解 ...
- (2010-8-31) awk内存泄漏以及缓慢的正则表达式计算速度
AWK内存泄露: 这几天本来就很郁闷,遇到搭建在hadoop平台上的hive平台有很多问题.写个好好的sql语句,总是说这个错误那个错误.然后,今天遇到一个更加郁闷的问题,居然分析淘宝数据的awk都运 ...
- 开心菜鸟学习系列笔记-----Javascript(1)
js 一些常见的使用方法 // target : 不管是否出现冒泡,他都是代表最开始引发事件的对象 // this : 是指当前函数. //ie 事件对象 : window ...
- VC-关于VC++ 6.0的那些事儿
Microsoft Visual C++,(简称Visual C++.MSVC.VC++或VC)微软公司的C++开发工具,具有集成开发环境,可提供编辑C语言,C++以及C++/CLI等编程语言.VC+ ...
- Database JDBC Developer's Guide
http://docs.oracle.com/database/121/JJDBC/datacc.htm#JJDBC28363
- highchart 实现mrtg
最近需要对流量图进行重构, <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- UVa 11401 三角形的个数
题意:由1,2,3...n组成的序列中找三个数,且以这三个数为变长能组成三角形,求这样的三角形个数. 思路:当每次输入n时重新都计算一遍会TLE...先预处理,将结果存入ans数组. 代码: #inc ...
- 《Two Days DIV + CSS》读书笔记——CSS选择器
1.1.2 CSS选择器 CSS 选择器最基本的有四种:标签选择器.ID 选择器.类选择器.通用选择器. [标签选择器] 一个完整的 HTML 页面由很多不同的标签组成,而标签选择器,则是决定哪些标签 ...
- tabbar 嵌套 navigation
-------------- 源代码:点击打开链接 ------------------------ AppDelegate.m - (BOOL)application:(UIApplication ...