ZOJ2227Minimax三角划分

Posted chanceyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ2227Minimax三角划分相关的知识,希望对你有一定的参考价值。

Despription

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?
技术图片
Figure 1: Five out of nine possible triangulations of the example polygon. The leftmost has the smallest largest triangle.

Instructions

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

Analysis

子结构是每次选取一个点,分成两块和一个三角形,然后找三者最大值,多次取点取最小值
三者比较表达方式max(a,max(b,c))

Code

#include<bits/stdc++.h>
using namespace std;
struct Node{
    int x,y;
}node[50];
int dp[50][50];
inline int S(Node& i,Node& k,Node& j){return abs(k.y*j.x-i.y*j.x-k.y*i.x-k.x*j.y+i.x*j.y+k.x*i.y);}
bool check(int &i,int &k,int &j,int &m){
    for(int r=0;r<m;++r)if(r==i||r==k||r==j)continue;
    else if(S(node[i],node[k],node[r])+S(node[i],node[j],node[r])+S(node[k],node[j],node[r])
==S(node[i],node[j],node[k]))return 0;
    return 1;
}
int main(){
    int n,i,j,m,k;scanf("%d",&n);
    for(int sq=0;sq<n;++sq){
        scanf("%d",&m);
        for(i=0;i<m;++i)scanf("%d%d",&node[i].x,&node[i].y);
        for(int z=2;z<m;++z)for(i=0;(j=i+z)<m;++i){
            dp[i][j]=70000000;
            for(k=i+1;k<j;++k){
                if(!check(i,j,k,m))continue;
                int t[3]={dp[i][k],dp[k][j],S(node[i],node[k],node[j])};
                dp[i][j]=min(dp[i][j],*max_element(t,t+3));
            }
        }
        printf("%.1f
",dp[0][m-1]/2.0);
    }
    return 0;
}

以上是关于ZOJ2227Minimax三角划分的主要内容,如果未能解决你的问题,请参考以下文章

ZOJ 3537 Cake (凸包 + 区间DP && 最优三角形剖分)

为啥保守光栅化无法为某些三角形调用片段着色器?

为啥这个 CSS 片段可以画一个三角形? [复制]

2021-12-24:划分字母区间。 字符串 S 由小写字母组成。我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。返回一个表示每个字符串片段的长度的列表。 力扣763。某大厂面试

ZOJ 3512 Financial Fraud (左偏树)

如何使用 xcode 将快照划分为多个片段,以便让用户与每个片段进行交互?