Description
Returns the coordinates of each point of a convex polygon for its area.
-
Input
-
Multiple Input groups. The first positive integer t represents the number of groups.
A positive integer N (1 ≤ n ≤ 1000) In the first line of each group indicates the number of vertices in the polygon,
In the next n + 1 line, each line has two integers, indicating the coordinates x and y of the polygon vertex. These polygon vertices are given in a counterclockwise order.
The line I (0 <I <n + 1) indicates the XI and Yi coordinates of the vertex I (within the int32 range ),
Line n + 1 is the coordinate of the first vertex. (Indicating the first and end of a polygon)
-
Output
-
Each group outputs a line with the area of the convex polygon, which retains a decimal number.
-
Sample Input
-
130 02 02 20 0
-
Sample output
-
2.0
Mathematical questions
# Include <iostream> # include <cmath> # include <iomanip> using namespace STD; int main () {int t; CIN> T; For (INT I = 0; I <t; I ++) {int N; CIN> N; double Total = 0; int * x = new int [n + 1]; int * Y = new int [n + 1]; for (Int J = 0; j <= N; j ++) {CIN> X [J]> Y [J];} int A [3], B [3], j = 0; double length [3]; int C; A [0] = x [0]; B [0] = Y [0]; do {for (C = 1; C <3; C ++) {A [c] = x [J + C]; B [c] = Y [J + C];} For (C = 0; C <3; C ++) {length [c] = SQRT (A [c]-A [(C + 1) % 3]) * (a [c]-A [(C + 1) % 3]) + (B [c]-B [(C + 1) % 3]) * (B [c]-B [(C + 1) % 3]);} Double P = length [0] + length [1] + length [2]; P/= 2; double S = 1; for (C = 0; C <3; C ++) {S * = p-length [c];} s = SQRT (S * P); Total + = s; j ++;} while (j <n-1); cout <setprecision (1) <fixed <total <Endl;} return 0 ;}