HDU 1392 凸包

时间:2021-02-20 00:19:30

Surround the Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10345    Accepted Submission(s): 4009

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.

HDU 1392  凸包

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
 
Sample Output
243.06
 
Source
 
题意:n个点 求凸包的周长
题解:凸包模板题
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
};
typedef point vec;
vec operator -(point a,point b)
{
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b)
{
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t)
{
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t)
{
return vec(a.x/t,a.y/t);
}
int dcmp(double x)
{
if(fabs(x)<=eps) return ;
return x<?-:;
}
double cross(vec a,vec b) ///叉积
{
return a.x*b.y-a.y*b.x;
}
bool cmp(point a,point b)
{
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
double disn(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
/*两点之间的距离*/
}
void convexhull(point *s,int &n)
{
sort(s,s+n,cmp);
int m=;
point p[];
for(int i=; i<n; i++)
{
while(m> && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
int k=m;
for(int i=n-; i>=; i--)
{
while(m>k && dcmp(cross(p[m-]-p[m-],s[i]-p[m-]))<=)
m--;
p[m++]=s[i];
}
m--;
n=m;
for(int i=; i<n; i++) s[i]=p[i];
/*建立凸包*/
}
int jishu;
int main()
{
while(scanf("%d",&jishu)!=EOF)
{
if(jishu==)
break;
point s[];
for(int i=; i<jishu; i++)
{
scanf("%lf %lf",&s[i].x,&s[i].y); }
if(jishu==)
{
printf("0.00\n");
continue;
}
if(jishu==)
{
printf("%.2f\n",disn(s[],s[]));
continue;
}
convexhull(s,jishu);
double sum=;
for(int i=; i<jishu-; i++)
{
sum+=disn(s[i],s[i+]);
}
sum+=disn(s[jishu-],s[]);
printf("%.2f\n",sum);
}
return ;
}

HDU 1392 凸包的更多相关文章

  1. HDU 1392 凸包模板题,求凸包周长

    1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...

  2. hdu 1392凸包周长

    //用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...

  3. HDU - 1392 凸包求周长&lpar;模板题&rpar;【Andrew】

    <题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...

  4. Surround the Trees HDU 1392 凸包

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

  5. HDU 1392 Surround the Trees(凸包入门)

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

  6. HDU - 1392 Surround the Trees &lpar;凸包)

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

  7. HDU 1392 Surround the Trees &lpar;凸包周长&rpar;

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

  8. HDU 4946 凸包

    给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...

  9. HDU 1392 Surround the Trees&lpar;凸包&ast;计算几何)

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

随机推荐

  1. Python:元组(tuple)

    #!/usr/bin/python3 #元组 tup1 = ('Google', 'Runoob', 1997, 2000) print(type(tup1)) print("tup1 &q ...

  2. jquery 验证框架的问题 remote的

    1.dataType 类型:String 预期服务器返回的数据类型.如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML.在 1 ...

  3. service structure flowchart &lbrack;mobile to server via HTTP RESTful API&rsqb;

    Modern flowchart for mobile, server, and etc.. communication This has something to do with these sou ...

  4. 异步编程Async&sol;await关键字

    异步编程Async \await 关键字在各编程语言中的发展(出现)纪实. 时间 语言版本 2012.08.15 C#5.0(VS2012) 2015.09.13 Python 3.5 2016.03 ...

  5. 使用* VSCode 扩展来加快开发 JavaScript

    使用* VSCode 扩展来加快开发 JavaScript 发表于 2018年08月24日 by 愚人码头 被浏览 3,942 次 分享到:   小编推荐:掘金是一个面向程序员的高质量技术社区,从 ...

  6. go语言使用go-sciter创建桌面应用&lpar;六&rpar; Element元素操作和Event事件响应

    详细的文档请看下面两个链接: https://sciter.com/docs/content/sciter/Element.htm https://sciter.com/docs/content/sc ...

  7. 集合框架二(Collection接口实现类常用遍历方法)

    四种常用遍历方式 Collection coll = new ArrayList(); coll.add("123"); coll.add("456"); co ...

  8. docker简易实践

    docker简易实践 实验环境 操作系统:deepin 15.4 安装步骤 1.安装docker sudo apt-get install docker.io 2.启动docker服务 sudo se ...

  9. 【Pyton】【小甲鱼】永久存储:腌制一缸美味的泡菜

    pickle(泡菜): picking:将对象转换为二进制 unpicking:将二进制转换为对象 1 >>> import pickle 2 #picking:对象导入到文件中(二 ...

  10. ios开发之--新手引导页的添加

    以往在写启动页面的时候,有时候会直接在启动页里面写,或者自带的vc里面直接写,但是那样并不是很方便,启动页里面往往会添加很多的东西,所以封装成一个单独的类,可以直接使用,即便是后期的更换,或者是其他的 ...