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
 
Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:  2150 1348 1147 1558 1374 
 
计算几何比较大小 判断正负 千万要用 sgn函数! 精度!精度!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 109
#define N 21
#define MOD 1000000
#define INF 1000000009
const double eps = 1e-;
const double PI = acos(-1.0);
/*
所有线段投射到给定线段上取交集,如果交集距离大于eps 存在!s
*/
int sgn(double x)
{
if (fabs(x) < eps) return ;
if (x < ) return -;
else return ;
}
struct Point
{
double x, y;
Point() {}
Point(double _x, double _y) :x(_x), y(_y) {}
Point operator - (const Point& r)const
{
return Point(x - r.x, y - r.y);
}
double operator ^(const Point& r)const
{
return x*r.y - y*r.x;
}
double operator * (const Point& r)const
{
return x*r.x + y*r.y;
}
};
double dist(Point a, Point b)
{
return sqrt((a - b)*(a - b));
}
struct Line
{
Point s, e;
Line() {}
Line(Point _a, Point _B) :s(_a), e(_B) {}
};
bool Seg_inter_line(Line l1, Line l2)
{
return sgn((l2.s - l1.e) ^ (l1.s - l1.e))*sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= ;
}
bool cross(Line l1, Line l2)
{
return
max(l1.s.x, l1.e.x) >= min(l2.s.x, l2.e.x) &&
max(l2.s.x, l2.e.x) >= min(l1.s.x, l1.e.x) &&
max(l1.s.y, l1.e.y) >= min(l2.s.y, l2.e.y) &&
max(l2.s.y, l2.e.y) >= min(l1.s.y, l1.e.y) &&
sgn((l2.s - l1.e) ^ (l1.s - l1.e))*sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= &&
sgn((l1.s - l2.e) ^ (l2.s - l2.e))*sgn((l1.e - l2.e) ^ (l2.s - l2.e)) <= ;
}
double CalcArea(Point p[], int n)
{
double res = ;
for (int i = ; i < n; i++)
res += (p[i] ^ p[(i + ) % n]) / ;
return fabs(res);
}
double CalcLen(Point p[],int n)
{
double res = ;
for (int i = ; i < n; i++)
res += dist(p[i], p[(i + ) % n]);
return (res);
}
bool isconvex(Point p[], int n)
{
bool s[];
memset(s, false, sizeof(s));
for (int i = ; i < n; i++)
{
s[sgn((p[(i + ) % n] - p[i]) ^ (p[(i + ) % n] - p[i])) + ] = true;
if (s[] && s[])
return false;
}
return true;
}
//Point Calgravitycenter(Point p[], int n)
//{
// Point res(0, 0);
// double area = 0;
// for (int i = 0; i < n; i++)
// {
// ci[i] = (p[i] ^ p[(i + 1) % n]);
// ti[i].x = (p[i].x + p[(i + 1) % n].x);
// ti[i].y = (p[i].y + p[(i + 1) % n].y);
// res.x += ti[i].x * ci[i];
// res.y += ti[i].y * ci[i];
// area += ci[i] / 2;
// }
// res.x /= (6 * area);
// res.y /= (6 * area);
// return res;
//}
Point L[MAXN],tmp[MAXN];
int Stack[MAXN], top;
bool cmp(Point p1, Point p2)
{
double tmp = (p1 - L[]) ^ (p2 - L[]);
if (sgn(tmp) > )
return true;
else if (sgn(tmp) == && sgn(dist(p1, L[]) - dist(p2, L[]) <= ))
return true;
else
return false;
}
double Graham(int n)
{
Point p0;
int k = ;
p0 = L[];
for (int i = ; i < n; i++)
{
if ((p0.y > L[i].y) || (p0.x == L[i].x&&p0.x > L[i].x) )
{
k = i, p0 = L[i];
}
}
swap(L[k], L[]);
sort(L + , L + n, cmp);
if (n == )
{
top = , Stack[] = ;
return 0.0;
}
else if (n == )
{
top = , Stack[] = , Stack[] = ;
return dist(L[],L[]);
}
Stack[] = , Stack[] = , top = ;
for (int i = ; i < n; i++)
{
while (top > && sgn((L[Stack[top - ]] - L[Stack[top - ]]) ^ (L[i] - L[Stack[top - ]])) <= )
{
top--;
}
Stack[top++] = i;
}
double res = ;
for (int i = ; i < top; i++)
res += dist(L[Stack[i]], L[Stack[(i + ) % top]]);
return res;
}
int main()
{
int n;
while (scanf("%d", &n), n)
{
for (int i = ; i < n; i++)
scanf("%lf%lf", &L[i].x, &L[i].y);
printf("%.2lf\n", Graham(n));
}
}

Surround the Trees HDU 1392 凸包的更多相关文章

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

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

  2. HDU 1392 凸包

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

  3. HDU 1392 Surround the Trees(几何 凸包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...

  4. hdu 1392凸包周长

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

  5. HDU - 1392 凸包求周长(模板题)【Andrew】

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

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

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

  7. HDU - 1392 Surround the Trees (凸包)

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

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

  9. hdu 1392 Surround the Trees 凸包模板

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

随机推荐

  1. Coursera Algorithms Programming Assignment 5: Kd-Trees (98分)

    题目地址:http://coursera.cs.princeton.edu/algs4/assignments/kdtree.html 分析: Brute-force implementation. ...

  2. Django day26 初识认证组件

    一:什么是认证组件 只有认证通过的用户才能访问指定的url地址,比如:查询课程信息,需要登录之后才能查看,没有登录,就不能查看,这时候需要用到认证组件 二:认证组件源码分析

  3. 《Typecript 入门教程》 1、类

    类 使用class + 类名 即可定义一个类,一个类中通常有3个成员:属性.构造函数.方法: 在类内部引用属性或方法事使用this调用,它表示我们访问的是类的成员. 我们使用new构造了Greeter ...

  4. ASP.NET MVC5 之路由器

    这篇博客介绍的很详细 http://www.cnblogs.com/yaozhenfa/p/asp_net_mvc_route_1.html

  5. 【知识总结】扩展卢卡斯定理(exLucas)

    扩展卢卡斯定理用于求如下式子(其中\(p\)不一定是质数): \[C_n^m\ mod\ p\] 我们将这个问题由总体到局部地分为三个层次解决. 层次一:原问题 首先对\(p\)进行质因数分解: \[ ...

  6. HDU4340 Capturing a country DP

    自己原来写的两个维度的DP有错,看了半天这个大牛的blog.http://blog.csdn.net/cyberzhg/article/details/7840922 题意:A军队和B军队要一起占领一 ...

  7. ACM_寻找第N小序列

    寻找第N小序列 Time Limit: 2000/1000ms (Java/Others) Problem Description: Now our hero finds the door to th ...

  8. css3通过scale()实现放大功能、通过rotate()实现旋转功能

    css3通过scale()实现放大功能.通过rotate()实现旋转功能,下面有个示例,大家可以参考下 通过scale()实现放大功能 通过rotate()实现旋转功能 而transition则可设置 ...

  9. Android RecyclerView遇到notifyDataSetChanged无效时的解决方案

    一.简述 不管AbsListView(ListView.GridView)或是新出的RecyclerView,在使用notifyDataSetChanged方法更新列表数据时,一定要保证数据为同个对象 ...

  10. 使用jquery animate实现锚点慢慢平滑滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...