题目连接: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. Spring Boot 系列教程18-itext导出pdf下载

    Java操作pdf框架 iText是一个能够快速产生PDF文件的java类库.iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的.它的类库尤其与java Servlet有很好 ...

  2. 二十四、oracle pl/sql 变量

    一.变量介绍在编写pl/sql程序时,可以定义变量和常量:在pl/sql程序中包括有:1).标量类型(scalar)2).复合类型(composite) --用于操作单条记录3).参照类型(refer ...

  3. 不使用jquery情况下循环添加绑定事件方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Merge into的使用详解-你Merge了没有【转】

    Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...

  5. pull类型消息中间件-消息消费者(二)

    消费者的实例化 关于consumer的默认实现,metaq有两种: DefaultMQPullConsumer:由业务方主动拉取消息 DefaultMQPushConsumer:通过业务方注册回调方法 ...

  6. 5-jQuery - AJAX get()/post()页面请求即执行

    get 前台页面 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> &l ...

  7. [妙味Ajax]第二课:实例:留言板、瀑布流

    知识点总结 瀑布流原理(固定布局) 总宽度大小固定 每列宽度固定,比如LI,高度自动计算,每列使用float:left来布局 计算最短的一列,将Div插到最短的一列处(li里面包div)(getSho ...

  8. iOS-Runtime机制详解

    一.简介 runtime是一套底层的纯c语言的API,我们写的代码在程序运行过程中都会被转化成runtime的C代码执行,例如[target doSomething];会被转化成objc_msgSen ...

  9. XmlNode和XmlElement区别

    今天在做ASP.NET操作XML文档的过程中,发现了两个类:XmlNode和XmlElement.这两个类的功能极其类似(因为我们一般都是在对Element节点进行操作).上网搜罗了半天,千篇一律的答 ...

  10. Codeforces Round #366 (Div. 2)_B. Spider Man

    B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...