HDU6219/POJ1259 [ICPC2017沈阳]Empty Convex Polygons 最大空凸包
Empty Convex Polygons
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 538 Accepted Submission(s): 138
Problem Description
Given a set of distinct points S on a plane, we define a convex hole to be a convex polygon having any of thegiven points as vertices and not containing any of the given points in its interior. In addition to the vertices, other given points may lie on the perimeter of the polygon. We want to find a convex hole as above forming the convexpolygon with the largest area.
Input
This problem has several test cases.
The first line of input contains an integer t (1 ≤ t ≤ 100) indicating the total number of cases. For each test case,the first line contains the integer n (3 ≤ n ≤ 50). Each of the following n lines describes a point with two integers x and y where -1000 ≤ x, y ≤ 1000.
We guarantee that there exists at least one non-degenerated convex polygon.
The first line of input contains an integer t (1 ≤ t ≤ 100) indicating the total number of cases. For each test case,the first line contains the integer n (3 ≤ n ≤ 50). Each of the following n lines describes a point with two integers x and y where -1000 ≤ x, y ≤ 1000.
We guarantee that there exists at least one non-degenerated convex polygon.
Output
For each test case, output the largest area of empty convex polygon, with the precision of 1 digit.
Remark: The corollary of Pick’s theorem about the polygon with integer coordinates in that says the area of it iseither ends to .0 or .5.
Remark: The corollary of Pick’s theorem about the polygon with integer coordinates in that says the area of it iseither ends to .0 or .5.
Sample Input
4
3
0 0
1 0
0 1
5
0 0
1 0
2 0
0 1
1 1
5
0 0
3 0
4 1
3 5
-1 3
6
3 1
1 0
2 0
3 0
4 0
5 0
Sample Output
0.5
1.5
17.0
2.0
求一个裸的最大空凸包,计算几何+DP真的要命...
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=100; const double zero=1e-8; struct Vector { double x,y; }; inline Vector operator -(Vector a,Vector b) { Vector c; c.x=a.x-b.x; c.y=a.y-b.y; return c; } inline double sqr(double a) { return a*a; } inline int Sign(double a) { if(fabs(a)<=zero)return 0; return a<0 ? -1:1; } inline bool operator <(Vector a,Vector b) { return Sign(b.y-a.y)>0||Sign(b.y-a.y)==0&&Sign(b.x-a.x)>0; } inline double Max(double a,double b) { return a>b ? a:b; } inline double Length(Vector a) { return sqrt(sqr(a.x)+sqr(a.y)); } inline double Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; } Vector dot[maxn],List[maxn]; double opt[maxn][maxn]; int seq[maxn]; int n,len; double ans; bool Compare(Vector a,Vector b) { int temp=Sign(Cross(a,b)); if (temp!=0)return temp>0; temp=Sign(Length(b)-Length(a)); return temp>0; } void Solve(int vv) { int t,i,j,_len; for(int ii=len=0;ii<n;ii++) { if(dot[vv]<dot[ii])List[len++]=dot[ii]-dot[vv]; } for(i=0;i<len;i++) for(j=0;j<len;j++) opt[i][j]=0; sort(List,List+len,Compare); double v; for(t=1;t<len;t++) { _len=0; for(i=t-1;i>=0&&Sign(Cross(List[t],List[i]))==0;i--); //cout<<i<<endl; while(i>=0) { v=Cross(List[i],List[t])/2.; seq[_len++]=i; for(j=i-1;j>=0&&Sign(Cross(List[i]-List[t],List[j]-List[t]))>0;j--); if(j>=0)v+=opt[i][j]; ans=Max(ans,v); opt[t][i]=v; i=j; } for(i=_len-2;i>=0;i--) opt[t][seq[i]]=Max(opt[t][seq[i]],opt[t][seq[i+1]]); } } int i; double Empty() { ans=0; for(i=0;i<n;i++) Solve(i); return ans; } int main() {//freopen("t.txt","r",stdin); int T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf%lf",&dot[i].x,&dot[i].y); printf("%.1lf\n",Empty()); } return 0; }