hdu_1392_Surround the Trees(凸包)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1392
题意:求凸包,不知道的百度
题解:模版题
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
/*
* 求凸包,Graham算法 * 点的编号0~n-1
* 返回凸包结果Stack[0~top-1]为凸包的编号
*/
const int MAXN = ;
const double eps = 1e-;
const double PI = acos(-1.0);
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;}//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B){double tx = x,ty = y,x = tx*cos(B) - ty*sin(B),y = tx*sin(B) + ty*cos(B);}
}list[MAXN];
int S[MAXN],top;//相对于list[0]的极角排序 double dist(Point a,Point b){return sqrt((a-b)*(a-b));}
bool _cmp(Point p1,Point p2){
double tmp =(p1-list[])^(p2-list[]);
if(sgn(tmp)>)return ;
else if(sgn(tmp)==&&sgn(dist(p1,list[])-dist(p2,list[]))<= )return ;
return ;
}
void Graham(int n){
Point p0=list[],tp;
int k=;
for(int i=;i<n;i++)if((p0.y > list[i].y)||(p0.y ==list[i].y&&p0.x>list[i].x))p0 =list[i],k=i;
tp=list[k],list[k]=list[],list[]=tp,sort(list+,list+n,_cmp);
if(n==){top=,S[]=;return;}
if(n==){top=,S[]=,S[]=;return;}
S[]=,S[]=,top=;
for(int i=;i<n;i++){
while(top>&&sgn((list[S[top-]]-list[S[top-]])^(list[i]-list[S[top-]]))<=)top--;
S[top++]=i;
}
} int main(){
int n;
while(~scanf("%d",&n),n){
for(int i=;i<n;i++)scanf("%lf%lf",&list[i].x,&list[i].y);
if(n==){puts("0.00");continue;}
else if(n==){printf("%.2lf\n",dist(list[],list[]));continue;}
Graham(n);
double ans=;
for(int i=;i<top-;i++)ans+=dist(list[S[i]],list[S[i+]]);
ans+=dist(list[S[]],list[S[top-]]);
printf("%.2lf\n",ans);
}
return ;
}
hdu_1392_Surround the Trees(凸包)的更多相关文章
- (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU-1392 Surround the Trees,凸包入门!
Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...
- 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(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- hdu1392 Surround the Trees 凸包
第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...
- hdu 1392 Surround the Trees 凸包裸题
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- Nginx下$_POST获取不到数据的解决方法
运行环境:windows+phpstorm+Nginx 步骤1:找到php.ini 配置文件,查找enable_post_data_reading变量,把Off改为On,确保其打开状态: 步骤2:将p ...
- Git Github jekyll,gem Liquid模板语言 Markdown
Git Git教程 常用 Git 命令清单 Git远程操作详解 使用jekyll建立个人网站 Git is a free and open source distributed version ...
- google浏览器图标显示不正常怎么办
taskkill /f /im explorer.exe rem 清理系统图标缓存数据库 attrib -h -s -r "%userprofile%\AppData\Local\IconC ...
- angularjs uigrid 中celltemplate的写浮动框
columnDefs: [ {field: 'collegename', enableFiltering: false ,width:"12%",displayName:" ...
- CodeForces 702B Powers of Two
简单题. 开一个$map$记录一下每个数字出现了几次,那么读入的时候$f[a[i]]+1$. 计算$a[i]$做出的贡献的时候,先把$f[a[i]]-1$,然后再枚举$x$,答案加上$f[{2^x} ...
- 计算机网络课程优秀备考PPT之第六章传输层(六)
为了记录自己从2016.9~2017.1的<计算机网络>助教生涯,也为了及时梳理和整写笔记! 前期博客是, 计算机网络课程优秀备考PPT之第一章概述(一) 计算机网络课程优秀备考PPT之第 ...
- 第六十四节,html文档布局元素
html文档布局元素 学习要点: 1.文档元素总汇 2.文档元素解析 本章主要探讨HTML5中文档元素,文档元素的主要作用是划分各个不同的内容,让整个布局清晰明快.让整个布局元 ...
- String类之substring--->查找某位置对应的字
以下方法都是java内置类String类的内置方法(不是构造方法哦,就是普通的方法),不需要我们写,直接拿过来用即可. substring方法对应Api介绍 查找字符串中的 从int beginI ...
- js--事件对象的理解3
实例2: 跟随鼠标的DIV-- <script> document.onmousemove=function (ev) { var oEvent=ev||event; var oDiv=d ...
- about hibernate lazy load and solution
about hibernate lazy load is that used when loaded again.it can increase efficienty and sava memory. ...