UVa1331

题目大意就是对一个多边形进行三角剖分。

wiki的三角剖分https://en.wikipedia.org/wiki/Triangulation_(geometry)

问怎么剖分使得最大三角形的面积最小。

对于凸多边形,都有状态转移方程

d(i, j) = Min{d(i, k), d(k,j), S(i, j, k)}

但是题目中给的不一定是凸多边形,则在对任意一个子多边形,如果有任意一个对角线i, j 和多边形中的任意一条边相交,则

设置d(i, j)为 无穷大即可,边界是d(i, i + 1) = 0

#include <bits/stdc++.h>
using namespace std;
const double DINF = 1000000000000;
int n;
struct Point{
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) {}
};

typedef Point Vector;
Vector operator + (Vector & A, Vector & B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector & A, Vector & B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector & A, double p) { return Vector(A.x * p, A.y * p); }
Vector operator / (Vector & A, double p) { return Vector(A.x / p, A.y / p); }
bool operator < (const Point & a, const Point & b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}
const double eps  =1e-10;
int dcmp(double x){
    if(fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
}

bool operator == (const Point & a, const Point & b){
    return dcmp(a.x-b.x) == 0 && dcmp(a.y - b.y) == 0;
}

double Dot(Vector & A, Vector & B){
    return A.x * B.x + B.y * A.y;
}

double Cross(Vector A, Vector B){
    return A.x * B.y - A.y * B.x;
}

double Area2(Point A, Point B, Point C){
    return fabs(Cross(B - A, C - A));
}

bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){
    double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),
        c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
    return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}

vector<Point> vex;
const int maxn = 300 + 5;
double d[maxn][maxn];
bool vis[maxn][maxn];

double S(int i, int k, int j){
    return Area2(vex[i], vex[k], vex[j]) / 2;
}

bool judge(int a, int b){
    for(int i = 1; i < vex.size(); ++i){
        if(SegmentProperIntersection(vex[a], vex[b], vex[i], vex[i - 1])) return true;
    }
    if(SegmentProperIntersection(vex[a], vex[b], vex[vex.size() - 1], vex[0])) return true;
    return false;
}

double dp(int i, int j){
    double & val = d[i][j];
    if(vis[i][j]) return val;
    vis[i][j] = true;
    if(j == i + 1) return val = 0;
    if(!(i == 0 && j == n - 1) && judge(i, j)) return val = DINF;
    val = DINF;
    for(int k = i + 1; k < j; ++k){
        val = min(val, max(S(i, k, j), max(dp(i, k), dp(k, j))));
    }
    return val;
}

int main()
{
    int T; scanf("%d", &T);
    while(T --){
        memset(vis, false, sizeof(vis));
        vex.clear();
        scanf("%d", &n);
        for(int i = 1; i <= n; ++i){
            int x, y;
            scanf("%d %d", &x, &y);
            vex.push_back(Point(x, y));
        }
        printf("%.1f\n", dp(0, n - 1));
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值