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.

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
0
 
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 凸包求周长(模板题)【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 (凸包)

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

  7. 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 ...

  8. HDU 4946 凸包

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

  9. HDU 1392 Surround the Trees(凸包*计算几何)

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

随机推荐

  1. 常见JS(JavaScript)冲突解决方法

    1.一般JS冲突解决办法 a.最容易出现的就是js的命名冲突 ①.变量名冲突 变量有全局变量和局部变量当全局变量变量和局部变量名称一致时,就会js冲突,由于变量传递数值或地址不同就会产生JavaScr ...

  2. bitmap格式分析

    位图(Bitmap)当然是最简单的,它Windows显示图片的基本格式,其文件扩展名为*.BMP.在Windows下,任何各式的图片文件(包括视频播放)都要转化为位图个时候才能显示出来,各种格式的图片 ...

  3. LCD驱动 15 -2

    1.分配一个fb_info结构体: framebuffer_alloc 2.设置 3.注册 4.硬件相关操 struct fb_fix_screeninfo { char id[16];   /* i ...

  4. Linux - gcc和g++的区别

    一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...

  5. 关于Xcode调试的帖子,感觉不错,转来看看

    http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 http://www.raywenderlich.com/10505 ...

  6. Non-Programmer's Tutorial for Python 3/File IO

    File I/O Here is a simple example of file I/O (input/output): # Write a file with open("test.tx ...

  7. 同是url参数传进来的值,String类型就用getAttribute获取不到,只能用getParameter获取,而int就两个都可以这是为什么?

    这是因为int的属性是id,这是在被放到modeldriver中的user所具有的属性,传递过来的参数如果和user的属性重名,struts2的有类似beanutil之类的工具会自动封装参数,这时候用 ...

  8. Javascript基础--成员函数(六)

    成员函数:也叫方法 1.常用方法 比如:我们希望对象不但有属性,还希望他有行为.(行为在程序中要靠函数来体现)(1) 添加speak函数,输出我是一个好人 (2) 添加jisuan函数,可以计算从1+ ...

  9. 修改Oracle数据库的字符集为UTF-8

    1.改客户端字符集:通过WINDOWS的运行菜单运行Regedit,修改注册表 Start -> Run -> Rededit <-| Under registry Editor - ...

  10. 《day17_String_StringBuffer》

    package cn.itcast.api.string; public class StringDemo{ public static void main(String[] args){ //定义一 ...