hdu 1392(凸包)
题意:求凸包的周长。
分析:凸包模板题,先按极角排好序后,然后根据叉积正负确定凸包。
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std; const double eps = 1e-;
const int N = ;
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 &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
};
double dist(Point a,Point b)
{
return sqrt((a-b)*(a-b));
}
Point p[N];
int Stack[N],top;
bool cmp(Point p1,Point p2)
{
double tmp=(p1-p[])^(p2-p[]);
if(sgn(tmp)==)return sgn(dist(p[],p1)-dist(p[],p2))<=;
return sgn(tmp)>;
}
void Graham(int n)
{
sort(p+,p+n,cmp);
Stack[]=;
Stack[]=;
top=;
for(int i=;i<n;i++)
{
while(top>&&sgn((p[Stack[top-]]-p[Stack[top-]])^(p[i]-p[Stack[top-]]))<=)top--;
Stack[top++]=i;
}
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y<p[].y||p[i].y==p[].y&&p[i].x<p[].x)
swap(p[],p[i]);
}
if(n==)puts("0.00");
else if(n==)printf("%.2lf\n",dist(p[],p[]));
else
{
Graham(n);
double ans=;
for(int i=;i<top;i++)
ans+=dist(p[Stack[i]],p[Stack[(i+)%top]]);
printf("%.2lf\n",ans);
}
}
return ;
}
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凸包周长
//用的自己的计算几何模板,不过比较慢嘿嘿 //要注意只有一个点和两个点 //Computational Geometry //by kevin_samuel(fenice) Soochow Univ ...
- HDU - 1392 凸包求周长(模板题)【Andrew】
<题目链接> 题目大意: 给出一些点,让你求出将这些点全部围住需要的多长的绳子. Andrew算法 #include<iostream> #include<cstdio& ...
- 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 ...
- 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 4946 凸包
给你n个点,具有速度,一个位置如果有其他点能够先到,则不能继续访问,求出里面这些点哪些点是能够无限移动的. 首先我们考虑到,一个速度小的和一个速度大的,速度小的必定只有固定他周围的一定区域是它先到的, ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- perl encode_json 会产生 UTF-8 (binary) string decode_json 需要一个 UTF-8 (binary) string
encode_json $json_text = encode_json $perl_scalar Converts the given Perl data structure to a UTF-8 ...
- 基于visual Studio2013解决C语言竞赛题之1026判断排序
题目 解决代码及点评 /********************************************************************** ...
- Android——内存调试
因调试某个重大问题,怀疑到了内存,专门写了个測试脚本.记录一下. 撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/details/37928823 一 ...
- 解决java mail发送TXT附件被直接显示在正文中的问题
这两天遇到一个问题,关于使用java mail发送邮件的问题. 详细是这样子的:我使用java mail发送异常报告邮件,邮件中有一个包含异常日志的附件,和关于设备信息的邮件正文.假设日志为log后缀 ...
- [转]java开发环境搭建
分成两个部分: 1.下载安装jdk,并配置环境变量 链接:http://www.runoob.com/java/java-environment-setup.html 2.安装Eclipse 链接:h ...
- Eclipse用法和技巧十五:自动添加未实现方法1
java代码中经常要实现一些接口,这个也是java代码独有的地方.实现接口,就意味着要实现这个接口中定义的方法,如果一个个去码出方法就需要记得方法名称等等,就算有内容辅助快捷键帮助,也是很麻烦的.这里 ...
- 更快地从IplImage转换成QImage
转:http://blog.sina.com.cn/s/blog_5c70dfc80100qzif.html 在Qt平台上使用OpenCV肯定会遇到从IplImage到QImage的转换问题,找了很多 ...
- python获取实时股票信息
Python3获取股票行情数据(中国个股/中国指数/全球指数) #!/usr/local/bin/python3 #coding=utf-8 #source http://www.cnblogs.co ...
- gbs build使用说明
注:本文从:https://source.tizen.org/documentation/articles/gbs-build 翻译而来. 1 前言 通过使用gbs build指令,开发者可以在本地编 ...
- 一百多道.NET面试题!
1.a=10,b=15,在不用第三方变量的前提下,把a,b的值互换 方法一: a=a+b; b=a-b; a=a-b; 方法二: a^=b^(b^=a^b); 2.已知数组int[] max= ...