凸包(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的速度在平面上移 ...
随机推荐
- T4 模板自动生成带注释的实体类文件
T4 模板自动生成带注释的实体类文件 - 只需要一个 SqlSugar.dll 生成实体就是这么简单,只要建一个T4文件和 文件夹里面放一个DLL. 使用T4模板教程 步骤1 创建T4模板 如果你没有 ...
- redhat 5下源码安装nginx服务
首先确保机器中已安装 gcc c++,libtool等工具,保证可执行源码安装 A.为了确保能在 Nginx 中使用正则表达式进行更灵活的配置,安装之前需要确定系统是否安装有 PCRE(Perl Co ...
- (转)Autotrace工具使用——小工具,大用场
监控SQL语句,获取执行计划和执行成本,是每个Oracle开发人员与DBA所必须具备的能力之一. 当Oracle彻底进入CBO时代,我们面对一种全新的局面.一方面,基于数据统计量的CBO优化器,让SQ ...
- hdu 1111 Secret Code
http://acm.hdu.edu.cn/showproblem.php?pid=1111 复数除法: #include <cstdio> #include <cstring> ...
- PagedList.MVC 应用
1. NuGet 下载 PagedList.MVC 2. View Page @model PagedList.IPagedList<Libaray.Models.Entities.BookMo ...
- PowerShell_零基础自学课程_1_初识PowerShell
欢迎转载本系列文章:转载请注明出处:www.cnblogs.com/volcanol 自从微软推出.Net以来,微软旗下的windows体系就发生了很大的变化,首先是操作系统的界面的变化,例如vist ...
- VM虚拟机安装苹果雪豹操作系统
1.win xp虚拟机安装Mac OSX 一.用VM8安装mac os x10.6 ,然后升级到的10.6.8,如何安装vm大家自己百度吧.这里指列出了如何安装雪豹操作系统. DMG是mac os x ...
- Tomcat查看用户名密码
在非安装版的tomcat中,可以在{解压路径}/conf/tomcat_users.xml 配置文件中找到,也可以自己添加新的用户
- 关于链表的一些重要操作(Important operations on a Linked List)
上篇博文中讨论了链表的一些基本操作: 链表的基本操作(Basic Operations on a Linked List) 然而,为创建一个多功能的链表,在深度学习之前我们还需要了解更多的链表操作. ...
- [Elasticsearch] 部分匹配 (三) - 查询期间的即时搜索
本章翻译自Elasticsearch官方指南的Partial Matching一章. 查询期间的即时搜索(Query-time Search-as-you-type) 如今让我们来看看前缀匹配可以怎样 ...