Minimax Triangulation - POJ 2066 dp+几何

来源:互联网 发布:seo免费培训教程 编辑:程序博客网 时间:2024/05/16 11:18

Minimax Triangulation
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 835 Accepted: 261

Description

Triangulation of surfaces has applications in the Finite Element Method of solid mechanics. The objective is to estimate the stress and strain on complex objects by partitioning them into small simple objects which are considered incompressible. It is convenient to approximate a plane surface with a simple polygon, i.e., a piecewise-linear, closed curve in the plane on m distinct vertices, which does not intersect itself. A chord is a line segment between two non-adjacent vertices of the polygon which lies entirely inside the polygon, so in particular, the endpoints of the chord are the only points of the chord that touch the boundary of the polygon. A triangulation of the polygon, is any choice of m - 3 chords, such that the polygon is divided into triangles. In a triangulation, no two of the chosen chords intersect each other, except at endpoints, and all of the remaining (unchosen) chords cross at least one of the chosen chords. Fortunately, finding an arbitrary triangulation is a fairly easy task, but what if you were asked to find the best triangulation according to some measure? 

Input

On the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing one positive integer 2 < m < 50, being the number of vertices of the simple polygon. The following m lines contain the vertices of the polygon in the order they appear along the border, going either clockwise or counter clockwise, starting at an arbitrary vertex. Each vertex is described by a pair of integers x y obeying 0 <= x <= 10 000 and 0 <= y <= 10 000.

Output

For each scenario, output one line containing the area of the largest triangle in the triangulation of the polygon which has the smallest largest triangle. The area should be presented with one fractional decimal digit.

Sample Input

167 06 29 53 50 31 1

Sample Output

9.0

题意:按顺时针或逆时针给你一个m边形,让你将它分成m-2个三角形,使得三角形中最大的面积最小。

思路:dp[i][j]表示从i到j点的最大的三角形的面积,每次dp[i][j]=min(dp[i][j],max(area(i,k,j),max(dp[i][k],dp[k][j])));

AC代码如下:

#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct node{    int x,y;}point[60];int T,t,n,dp[60][60],INF=1e9;int multiply(int a,int b){    return point[a].x*point[b].y-point[a].y*point[b].x;}int area(int a,int b,int c){    int ret=multiply(a,b)+multiply(b,c)+multiply(c,a);    if(ret>0)      return ret;    else      return -ret;}bool judge(int a,int b,int c){    int ret=area(a,b,c),p;    for(p=1;p<=n;p++)    {        if(p==a || p==b || p==c)          continue;        if(ret==area(a,b,p)+area(a,c,p)+area(b,c,p))          return false;    }    return true;}int main(){    int i,j,k,p;    scanf("%d",&T);    for(t=1;t<=T;t++)    {        scanf("%d",&n);        for(i=1;i<=n;i++)           scanf("%d%d",&point[i].x,&point[i].y);        for(i=1;i<=n-2;i++)           dp[i][i+2]=area(i,i+1,i+2);        for(p=3;p<n;p++)           for(i=1;i+p<=n;i++)           {               j=i+p;               dp[i][j]=INF;               for(k=i+1;k<=j-1;k++)                  if(judge(i,k,j))                    dp[i][j]=min(dp[i][j],max(area(i,k,j),max(dp[i][k],dp[k][j])));           }        printf("%.1f\n",dp[1][n]/2.0);    }}



0 0