最大空凸包模板
Posted 啦啦啦天啦噜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最大空凸包模板相关的知识,希望对你有一定的参考价值。
inline double sgn(double x, double y) { return fabs(x-y)<eps; } inline int sgn(int x, int y) { return x==y; } struct point { double x,y; }; double cross(point a, point b, point o) { return (a.x-o.x)*(o.y-b.y)-(a.y-o.y)*(o.x-b.x); } double dist(point a, point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } point o; bool cmp_angle(point a,point b) { if(sgn(cross(a,b,o),0.0)) { return dist(a,o)<dist(b,o); } return cross(a,o,b)>0; } double empty_convex(point p[], int pn) { double ans=0; memset(dp,0,sizeof(dp)); for(int i=0; i<pn; i++) { int j = i-1; while(j>=0 && sgn(cross(p[i], p[j], o),0.0)) j--;//coline bool flag= j==i-1; while(j>=0) { int k = j-1; while(k >= 0 && cross(p[i],p[k],p[j])>0) k--; double area = fabs(cross(p[i],p[j],o))/2; if(k >= 0)area+=dp[j][k]; if(flag) dp[i][j]=area; ans=max(ans,area); j=k; } if(flag) { for(int j=1; j<i; j++) { dp[i][j] = max(dp[i][j],dp[i][j-1]); } } } return ans; } double largest_empty_convex(point p[], int pn) { point data[maxn]; double ans=0; for(int i=0; i<pn; i++) { o=p[i]; int dn=0; for(int j=0; j<pn; j++) { if(p[j].y>o.y||(p[j].y==o.y&&p[j].x>=o.x)) { data[dn++]=p[j]; } } sort(data, data+dn, cmp_angle); ans=max(ans, empty_convex(data, dn)); } return ans; }
以上是关于最大空凸包模板的主要内容,如果未能解决你的问题,请参考以下文章
Game of Taking Stones && POJ1259 /// 最大空凸包 几何+DP
poj1259The Picnic & hdu6219 Empty Convex Polygon(17沈阳区域赛C)最大空凸包