题目连接: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(凸包)的更多相关文章

  1. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

    称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. hdu 1392 Surround the Trees 凸包模板

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

  3. hdu 1392 Surround the Trees (凸包)

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

  4. HDU-1392 Surround the Trees,凸包入门!

    Surround the Trees 此题讨论区里大喊有坑,原谅我没有仔细读题还跳过了坑点. 题意:平面上有n棵树,选一些树用绳子围成一个包围圈,使得所有的树都在这个圈内. 思路:简单凸包入门题,凸包 ...

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

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

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

  7. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  8. hdu1392 Surround the Trees 凸包

    第一次做凸包,这道题要特殊考虑下,n=2时的情况,要除以二才行. 我是从最左边的点出发,每次取斜率最大的点,一直到最右边的点. 然后从最左边的点出发,每次取斜率最低的点,一直到最右边的点. #incl ...

  9. hdu 1392 Surround the Trees 凸包裸题

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

随机推荐

  1. JavaScript DOM编程艺术-学习笔记(第十二章)

    第十二章 1.本章是综合前面章节的所有东西的,一个综合实例 2.流程:①项目简介:a.获取原始资料(包括文本.图片.音视频等) b.站点结构(文件目录结构) c.页面(文件)结构 ②设计(切图) ③c ...

  2. Windows Server 2008 如何在IIS中添加MIME类型

    用户可以通过使用MIME以设置服务器传送多媒体文件,如声音和视频等.MIME是一种技术规范,现在可以用于浏览器上,传送可以供浏览器识别的信息 如果我们的网站提供下载服务,有时传上去的文件比如 xxx. ...

  3. Mysql存储过程和函数

    Mysql存储过程和函数 基本概念: 创建存储过程和函数是指将经常使用的一组SQL语句的组合在一起,并将这些SQL语句当作一个整体存储在MySQL服务器中.例如,银行经常需要计算用户的利息.不同类别的 ...

  4. JavaScript 属性类型(数据属性 访问器属性)

    ECMA-2把对象定义为:“无序属性的集合,其属性可以包含基本值.对象或者函数.” 严格来说,这就相当于说对象是一组没有特定顺序的值.对象的属性或方法都有一个名字,而每个名字映射到一个值.我们可以把E ...

  5. 重点+超详细:ajax和json及案例

    不用jQuery的ajax流程 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht ...

  6. Maven+STS工程中Maven Dependencies 文件夹丢失问题

    在我们使用Maven+sts工程中偶尔会出现这种情况: Maven Dependencies文件夹在新打开的工程中丢失,造成 web project 自动编译出错,缺少必要的库文件: 如下图所示的情况 ...

  7. 【转】MapReduce的优化

    相信每个程序员在编程时都会问自己两个问题“我如何完成这个任务”,以及“怎么能让程序运行得更快”.同样,MapReduce计算模型的多次优化也是为了更好地解答这两个问题. MapReduce计算模型的优 ...

  8. Listview性能优化

    首先,虽然大家都知道,还是提一下,利用好 convertView 来重用 View,切忌每次 getView() 都新建.ListView 的核心原理就是重用 View.ListView 中有一个回收 ...

  9. /tmp 和 /var/tmp 的区别

    /tmp is meant as fast (possibly small) storage with a short time to live (TTL). Many systems clean / ...

  10. JSP+Servlet实现上传下载

    0.项目结构 1.在WebRoot下创建index.jsp页面 <%@ page language="java" import="java.util.*" ...