HDOJ 2036 多边形的面积
整数坐标下,面积的2倍也是整数;
多边形面积公式;
# include <stdio.h> # define N 105 int n; int x[N], y[N]; double area(void) { int i; double ret; ret = 0; for (i = 0; i < n-1; ++i) { ret += x[i]*y[i+1] - x[i+1]*y[i]; } ret += x[n-1]*y[0] - x[0]*y[n-1]; return ret*0.5; } int main() { int i; while (~scanf("%d", &n)) { if (n == 0) break; for (i = 0; i < n; ++i) scanf("%d%d", &x[i], &y[i]); printf("%.1lf\n", area()); } return 0; }
//