1 /** 2 对多边形A1A2A3...An(顺或逆时针都可以,逆时针的话就不用加绝对值了~),设平面上有任意的一点P(0,0),则有: 3 S(A1,A2,A3,... ,An) = abs(S(P,A1,A2) + S(P,A2,A3)+...+S(P,An,A1)) 4 也就是说,假设Ai坐标为(xi,yi),则 5 S(A1,A2,A3,... ,An) =abs(1/2 *(x1y2 - x2y1 + x2y3 - x3y2 + ... + xn-1yn - xnyn-1)) 6 7 输入: 8 n——测试多边形的个数 9 m——当前多边形的点的个数 10 x1, y1, x2, y2,...xm, ym 11 12 输出: 13 多边形的面积 14 15 样例输入: 16 1 17 0 0 0 1 1 1 1 0 18 19 样例输出: 20 1 21 */ 22 23 #include<cstdio> 24 #include<cmath> 25 26 struct POINT 27 { 28 int x; 29 int y; 30 }point[101];// 31 32 int main() 33 { 34 int n, m, sum; 35 double result; 36 scanf_s("%d", &n); 37 while(n --) 38 { 39 scanf_s("%d", &m); 40 for(int i = 1 ; i <= m ; i ++) 41 { 42 scanf_s("%d%d", &point[i].x, &point[i].y); 43 } 44 45 int sum = 0; 46 for(int i = 1 ; i < m ; i ++) 47 { 48 if(i != m) 49 sum += (point[i].x * point[i +1].y - point[i].y * point[i + 1].x); 50 else 51 sum += (point[i].x * point[1].y - point[i].y * point[1].x); 52 } 53 54 result = (double)sum/2; 55 printf_s("%lf ", abs(result)); 56 } 57 58 return 0; 59 }