Surround the Trees HDU 1392 凸包
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.
Zero at line for number of trees terminates the input for your program.
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0
#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 凸包的更多相关文章
- HDU 1392 凸包模板题,求凸包周长
1.HDU 1392 Surround the Trees 2.题意:就是求凸包周长 3.总结:第一次做计算几何,没办法,还是看了大牛的博客 #include<iostream> #inc ...
- HDU 1392 凸包
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1392 Surround the Trees(几何 凸包模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1392 题目大意: 二维平面给定n个点,用一条最短的绳子将所有的点都围在里面,求绳子的长度. 解题思路: 凸包的模 ...
- hdu 1392凸包周长
//用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...
- HDU - 1392 凸包求周长(模板题)【Andrew】
<题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...
- HDU 1392 Surround the Trees(凸包入门)
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU - 1392 Surround the Trees (凸包)
Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...
- 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 ...
- hdu 1392 Surround the Trees 凸包模板
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- Rails 服务器架设失败问题
更新: 2017/09/14 补充了简单的确认号码的方法 A server is already running. Check /Users/...../pids/server.pid. Exitin ...
- P4166 [SCOI2007]最大土地面积
传送门 首先,四边形的四个点肯定都在凸包上(别问我为什么我也不知道,感性理解一下好了) 那么我们可以求出凸包之后\(O(n^4)\)暴力枚举,据说在随机数据下凸包上的点只有\(O(logn)\)个可过 ...
- Akka源码分析-故障恢复
Actor故障恢复是akka中非常重要的内容,在之前的博客中虽然有介绍,但都是杂糅在其他知识点的细节中,本博客将单独介绍这一部分的故障恢复.为了简化分析的单独,本文只研究用户的actor故障恢复的步骤 ...
- 一种高兼容性的JavaBean序列化方案
在对JavaBean做序列化时,我们可能在某些场景希望前后兼容性好一些.比如所有的javaBean都序列化后保存在数据库,用的时候需要反序列化创建.随着业务的发展,数据模型可能会进行变更,那么原来的数 ...
- Hadoop Hive概念学习系列之hive里的扩展接口(CLI、Beeline、JDBC)(十六)
<Spark最佳实战 陈欢>写的这本书,关于此知识点,非常好,在94页. hive里的扩展接口,主要包括CLI(控制命令行接口).Beeline和JDBC等方式访问Hive. CLI和B ...
- IIS 503 错误
今天早上乘公交的时候,网站运维群里直接炸了,网站打不开,503错误.然后就各种@我,吓得我手机都要扔了,然后马不停蹄的赶往公司去查看错误. 我首先在IIS上浏览网页,想试图在服务器上显现出详细错误,这 ...
- 【反射】Java反射机制
Class 1.Class是一个类,一个描述类的类(也就是描述类本身),封装了描述方法的Method,描述字段的Filed,描述构造器的Constructor等属性 2.对象照镜子后(反射)可以 ...
- Hive扩展功能(七)--Hive On Spark
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...
- java web项目和java项目的区别(看清IDE本质)
想必大家在使用MyEclipse时对这两个概念不去深究.只知道是Java EE类的基本都是Web项目,而Java应用程序就是Java项目.而且很多人都愿意使用MyEclipse作为开发工具,且不说大家 ...
- Caffe:导入caffePython-PyQt failed
在另一台电脑上使用caffe python版本,显示 Backend Qt5Agg is interactive backend. Turning interactive mode on. ...