Uva 1331-minimax Triangulation (optimal triangulation inter-partition DP)

Source: Internet
Author: User

The main topic: according to the order of the clockwise or counter-clockwise to give a multilateral point, to break this polygon into a n-2 triangle, the requirements of these triangular rows of the largest area of the Triangle area as small as possible, to find the minimum value.

Ideas: with the interval DP can be easily solved, The polygon may be a concave shape, note that the triangle must be inside the polygon, so you can remove the split triangle contains other points, but other in the polygon outside the triangle did not think of other methods to remove, but AC, do not understand why

acceptedc++0.042#include<cstdio> #include <iostream> #include <algorithm> #include <cstring > #include <cmath>using namespace std; #define INF 0x3f3f3f3fconst double ESP = 1e-6;int n;struct point{Double X , Y;} POI[55];d ouble dp[55][55];d ouble Area (point A,point b,point c) {return fabs ((b.x-a.x) * (C.Y-A.Y)-(c.x-a.x) * ( B.Y-A.Y))/2.0;} BOOL Judge (int a,int b,int c) {for (int i = 1;i<=n;i++) {if (i==a| | i==b| |        I==C) continue;        Double S=area (poi[i],poi[a],poi[b]) +area (Poi[i],poi[b],poi[c]) +area (Poi[i],poi[c],poi[a]);    if (Fabs (S-area (poi[a],poi[b],poi[c)) <esp) return true; } return false;}    int main () {int T;    scanf ("%d", &t);        while (t--) {memset (dp,0,sizeof (DP));        scanf ("%d", &n);        for (int i=1;i<=n;i++) {scanf ("%lf%lf", &poi[i].x,&poi[i].y); } for (int l=2;l<n;l++) for (int p=1;p+l<=n;p++) {dp[p][p+l]=inf;                    for (int k=p+1;k<p+l;k++) {if (judge (p,k,p+l)) continue;                Dp[p][p+l]=min (Dp[p][p+l],max (Max (dp[p][k],dp[k][p+l]), area (Poi[p],poi[k],poi[p+l]));    }} printf ("%.1f\n", Dp[1][n]); } return 0;}


Uva 1331-minimax Triangulation (optimal triangulation inter-partition DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.