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 ...
随机推荐
- NDK常见错误
1.错误1: android mk文件没有定义 $ ndk-buildAndroid NDK: Your APP_BUILD_SCRIPT points to an unknown file: /cy ...
- html5权威指南:表格元素
第十一章:表格元素 ...
- Spring Security(09)——Filter
目录 1.1 Filter顺序 1.2 添加Filter到FilterChain 1.3 DelegatingFilterProxy 1.4 FilterChainPr ...
- (负)-margin在页面布局中的应用
有关margin的原理可以看看这篇文章:http://www.cnblogs.com/2050/archive/2012/08/13/2636467.html#2457812 有关margin负值的几 ...
- JS之链式运动,及任意值运动框架,包括透明度的改变
链式运动,顾名思义,一环扣一环,即执行完一个事件后,再接着执行下一个事件,在参数上面动手脚,将下一个要执行的函数名作为一个参数,即利用到回掉函数,下面代码中出现的fn,即回掉函数, function ...
- fatal error RC1004: unexpected end of file found处理方法
资源编译器错误 RC1004 错误消息 遇到意外的文件结束 此错误是由于文本文件的最后一行中缺少换行符和回车符而造成的.
- cmd alias 自定义命令
简短步骤:1.关闭所有在运行的CMD窗口2.创建文件C:\cmd-alias.bat,包含以下内容:[python] view plain copydoskey sayhello=echo Hello ...
- Tyvj-TOM的无穷序列
背景 蛟川书院模拟试题 描述 TOM有一个无穷序列中如下:110100100010000100000.....请你帮助TOM找出在这个无穷序列中指定位置上的数字 输入格式 第一行一个正整数N,表示询问 ...
- js 中创建对象
对象是什么 从JavaScript定义上讲对象是无序属性的集合,其属性可以包含基本值.对象或函数.也就是说对象是一组没有特定顺序的属性,每个属性会映射到一个值上,是一组键值对,值可以是数据或对象. 最 ...
- Error establishing socket解决办法
jdbc配置语句为: jdbc:microsoft:sqlserver://server_name:1433 如运行程序时出现 "Error establishing socket" ...