Convex Polygon optimal triangle division
(16:38:40 )[Edit] [Delete]
ReprintedBytes
| Tags:It |
Category: Algorithm |
Convex Polygon optimal triangle division
Note:
P = {v0, V1,... vn-1} represents a convex side with N side v0, V1, v1v2,..., vn-1vn. V0 = Vn
1. Structure of triangle partitioning and related issues
Number of operators in a polygon
You can define the weight function w on a triangle, for example
W (vi vj VK) = | vi vj | + | Vi VK | + | VJVK | = pipj PK
2. Optimal sub-structure:
When v0vkvn is set, the n + 1 edge P = {v0, V1 ,..., Vn} is divided into three parts: {v0, V1 ,..., VK}, {VK, VK + 1 ,..., The best Partitioning Method for vn} and {v0, VK, vn}, then the convex polygon {v0, V1 ,..., The partitioning of VK} must be optimal. {VK, VK + 1 ,..., The division of vn} must be optimal.
Setting {v0, V1 ,..., The Weight Function of the vn} triangle is C, {v0, V1 ,..., The Weight Function of the VK} triangle is A, {VK, VK + 1 ,..., The Weight Function of the vn} triangle is B. If the weight function of the triangle v0vkvn is W (v0vkvn), c = a + B + W (v0vkvn ).
If C is the smallest, it must contain a and B are the smallest. If a is not the smallest, it corresponds to {v0, V1 ,..., The VK} is not the best. For convex polygon {v0, V1 ,..., For VK}, there must be an optimal triangle, with {v0, V1 ,..., The sum of the weight function corresponding to the optimal triangle division of VK} is A' ('
3. recursive structure of optimal triangle partitioning
First define T [I] [J], 1 <= I <= j <= N for Convex Polygon {vi-1, v I ,..., the weight function value corresponding to the optimal triangle of VJ}, that is, its optimal value .. Set the degradation of the polygon {vi-1, VI} polygon with the weight of 0. According to the definition, the optimal weight of the convex (n + 1) edge P to be calculated T [1] [N].
The value of T [I] [J] can be recursively calculated using the optimal sub-structure. Because the weight of the two degraded vertex polygon is 0, T [I] [I] = 0, I =,..., n. When J-I> = 1, the convex sub-polygon {vi-1, v I,..., VJ} has at least three vertices. Based on the optimal sub-structure, the value of T [I] [J] should be the value of T [I] [k] plus the value of T [k + 1] [J, add the vi-1vkvj weight, where I <= k <= J-1. since the locations of K are unknown during calculation, and all possible locations of K are only J-I, the T [I] [J] value can be selected to the smallest position in the J-I position. Therefore, t [I] [J] can be recursively defined
0 I = J
T [I] [J]
Min {T [I] [k] + T [k + 1] [J] + W (vi-1 VK VJ )} J
4. Calculate the optimal value
# Include
# Include "stdio. H"
# Include "math. H"
Int ABS (int B)
{
Returnb> 0? B:-B;
}
Using namespace STD;
Struct Node
{
Double X;
Double Y;
} Nums [160];
Double T [1, 160] [2, 160];
Double distance (int I, int K, Int J, int N)
{
Double temp1 = 0, temp2 = 0, temp3 = 0;
If (ABS (k-I) <= 1 | ABS (k-I)> = N-1)
Temp1 = 0;
Else
Temp1 = SQRT (Nums [I]. x-nums [K]. x) * (Nums [I]. x-nums [K]. x) + (Nums [I]. y-nums [K]. y) * (Nums [I]. y-nums [K]. Y ));
If (ABS (J-k) <= 1 | ABS (J-k)> = N-1)
Temp2 = 0;
Else
Temp2 = SQRT (Nums [K]. x-nums [J]. x) * (Nums [K]. x-nums [J]. x) + (Nums [K]. y-nums [J]. y) * (Nums [K]. y-nums [J]. Y ));
If (ABS (J-I) <= 1 | ABS (J-I)> = N-1)
Temp3 = 0;
Else
Temp3 = SQRT (Nums [I]. x-nums [J]. x) * (Nums [I]. x-nums [J]. x) + (Nums [I]. y-nums [J]. y) * (Nums [I]. y-nums [J]. Y ));
Return temp1 + temp2 + temp3;
}
Double mint (int n)
{
Int I, j, R, K;
Double Q;
For (I = 1; I <= N; I ++)
T [I] [I] = 0;
For (r = 2; r <= N; r ++)
{
For (I = 1; I <= N-R + 1; I ++)
{
J = I + R-1;
T [I] [J] = 1E + 10;
For (k = I; k <= J-1; k ++)
{
Q = T [I] [k] + T [k + 1] [J] + distance (I-1, K, J, N );
If (Q
T [I] [J] = Q;
}
}
}
Return T [1] [N];
}
IntMain ()
{
Int N, J, size;
Double num;
Cin> size;
For (j = 0; j
Cin> Nums [J]. x> Nums [J]. Y;
Nums [J]. x = Nums [0]. X;
Nums [J]. Y = Nums [0]. Y;
Num = mint (size)/2;
Printf ("% 0.3f \ n", num );
Return 0;
}