码迷,mamicode.com
首页 > 其他好文 > 详细

(凸包模板)(刘汝佳)

时间:2014-08-16 16:20:40      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:os   for   amp   return   c   oo   struct   模板   

struct point
{
int x,y;
} p[N],stack[N];

bool cmp(point A,point B)
{
if(A.y==B.y)return A.x<B.x;
return A.y<B.y;
}
int cross(point A,point B,point C)
{
return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);
}
void graham()
{
sort(p,p+n,cmp);
int i;
top=0;
for(i=0; i<n; i++)
{
while(top>1&&cross(stack[top-2],stack[top-1],p[i])<0)
{
top--;
}
stack[top++]=p[i];
}
int t=top;
for(i=n-2; i>=0; i--)
{
while(top>t&&cross(stack[top-2],stack[top-1],p[i])<0)
top--;
stack[top++]=p[i];
}
if(n>1)
top--;
}

(凸包模板)(刘汝佳),布布扣,bubuko.com

(凸包模板)(刘汝佳)

标签:os   for   amp   return   c   oo   struct   模板   

原文地址:http://www.cnblogs.com/lxm940130740/p/3916440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!