poj 2066

Minimax Triangulation
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 820 Accepted: 255

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

1
6
7 0
6 2
9 5
3 5
0 3
1 1

Sample Output

9.0

Source

Northwestern Europe 2004
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define maxn 10e9
#define eps 1e-8
using namespace std;
double s[55][55][55];
double d[55][55];
int n,m;

struct Point
{
    double x,y;
} p[55];

double cross(Point a, Point b, Point c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

double area(Point a, Point b, Point c)
{
    return fabs(cross(a, b, c)/2.0);
}

bool judge(int i, int k, int j)
{
    for(int t=0; t<m; t++)
    {
        if(t==i||t==k||t==j) continue;
        double tmp=area(p[i],p[k],p[j])-area(p[i],p[j],p[m])-area(p[i],p[k],p[m])-area(p[j],p[k],p[m]);
        if(fabs(tmp-s[i][k][j])<eps)
            return false;
    }
    return true;
}

int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    while(n--)
    {
        memset(d,0,sizeof(d));
        cin>>m;
        for(int i=0; i<m; i++)
            cin>>p[i].x>>p[i].y;
        for(int i=0; i<m; i++)
            for(int j=0; j<m; j++)
                for(int k=0; k<m; k++)
                    s[i][k][j]=area(p[i],p[k],p[j]);
        for(int l=2; l<=m-1; l++)
            for(int i=0; i+l<=m-1; i++)
            {
                int  j=i+l;
                d[i][j]=maxn;
                for(int k=i+1; k<j; k++)
                    if(judge(i,k,j))
                        d[i][j]=min(d[i][j],max(s[i][k][j],max(d[i][k],d[k][j])));
            }
        printf("%.1lf\n",d[0][m-1]);
    }
    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值