/*
*  求简单多边形面积 
*/ 

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 105;

struct point {
	int x;
	int y;
}p[N];

int crossProd(point A, point B) {
	return A.x*B.y - A.y*B.x;
}

int compArea(int n) {
	p[n] = p[0];
	int area = 0;
	for (int i=0; i<n; ++i) area += crossProd(p[i], p[i+1]);
	return area / 2;
}

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		for (int i=0; i<n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
		int area = compArea(n);
		printf ("%d\n", area);
	}
	return 0;
} 

  

相关文章:

  • 2021-06-26
  • 2021-08-08
  • 2021-04-26
  • 2022-12-23
  • 2021-07-27
  • 2022-01-06
  • 2022-02-22
  • 2022-12-23
猜你喜欢
  • 2021-05-02
  • 2021-12-31
  • 2021-12-06
  • 2021-07-13
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案