Test instructions: Enter a simple m (2<m<50) edge to find the smallest triangulation of the largest triangle (dividing a polygon into triangles with disjoint diagonal lines). Outputs the largest triangular area.
Analysis: Each diagonal is unordered, therefore, to the node number, from 1 to n-1, clockwise direction, so that the vertices of the polygon are ordered, so that can be divided into intervals, similar to the interval DP to do.
#include <bits/stdc++.h>using namespacestd;Const intmaxn= -;Const Doubleinf=0x3f3f3f3f;Const Doubleeps=1e-9;DoubleD[MAXN][MAXN];intN;structpoint{Doublex, y; void Get() {scanf ("%LF%LF",&x,&y); }}P[MAXN];DoubleArea (Point a,point b,point c) {returnFabs ((b.x-a.x) * (C.Y-A.Y)-(c.x-a.x) * (B.Y-A.Y))/2;}BOOLJudgeintAintBintc) { DoubleAre=Area (P[a],p[b],p[c]); for(intI=0; i<n;i++) { if(i==a| | i==b| | I==C)Continue; DoubleTmp=area (P[a],p[b],p[i]) +area (P[a],p[c],p[i]) +Area (P[b],p[c],p[i]); if(Fabs (are-tmp) <eps)return false; } return true;}Doublesolve () { for(intI=0;i<2; i++) for(intj=0; j<n;j++) d[j][(J+i)%n]=0; for(intI=0; i<n;i++) d[i][(i+2)%n]=area (p[i],p[(i+1)%n],p[(i+2)%n]); for(intk=3; k<n;k++) { for(intI=0; i<n;i++) { inten= (i+k)%N; D[i][en]=inf; for(intJ= (i+1)%n;j!=en;j= (j+1)%N)if(judge (I,en,j)) D[i][en]=min (D[i][en],max (max (D[i][j],d[j][en]), area (P[i],p[j],p[en])); } } Doubleans=inf; for(intI=0; i<n;i++) ans=min (ans,d[i][(i+n-1)%n]); returnans;}intMain () {intT; CIN>>T; while(t--) {cin>>N; for(intI=0; i<n;i++) P[i].Get(); printf ("%.1lf\n", Solve ()); } return 0;}
Triangulation of uva1331