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 ...
随机推荐
- 【WIP】Ruby CSV文件操作
创建: 2017/09/30 ...
- 清北刷题班day3 morning
P99zhx: 竞赛时间:???? 年?? 月?? 日??:??-??:??题目名称 a b c名称 a b c输入 a.in b.in c.in输出 a.out b.out c.out每个测试点时限 ...
- JavaScript中相等==和严格相等===的区别
在JavaScipt中==(相等)和===(严格相等,strick equality 也有译作“恒等”.“全等”)用于比较两个值是否相等,两个运算符允许任意类型的操作数.如果操作数相等则返回true, ...
- ibatis 基类生成
using IBatisNet.Common.Utilities; using IBatisNet.DataMapper; using IBatisNet.DataMapper.Configurati ...
- 爬虫—Ajax数据爬取
一.什么是Ajax 有时候我们使用浏览器查看页面正常显示的数据与使用requests抓取页面得到的数据不一致,这是因为requests获取的是原始的HTML文档,而浏览器中的页面是经过JavaScri ...
- JSP 向 JavaScript 中传递数组
采用隐藏标签的方式: // JSP: <% while(rs.next()) { %> <in ...
- 5CSS之字体font-family
---------------------------------------------------------------------------------------------------- ...
- 3 工欲善其事必先利其器,C#开发环境准备
1. 为什么选择C#作为入门的编程语言开始学习? Java和C#是比较主流的两大开发语言.(除了这两种还有什么比较流行的开发语言?)相对于Java,C#的入门要容易一些.学习java开发需 ...
- Spring Cloud (10) Hystrix-监控面板
Hystrix DashBoard 断路器是根据一段时间窗内的请求状况来判断并操作断路器的打开和关闭状态的.Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界 ...
- JS高级——arguments
arguments 1.函数内部的一个对象,在函数调用的时候,默认的会将所有传入的实参依次存入该对象 2.是一个伪数组 3.arguments.length 可以用来表示传入实参的个数 4.argum ...