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; }
时间: 2024-10-10 09:03:03