叉积求三角形面积公式和求多边形面积公式可参考下面的博客
https://www.cnblogs.com/xiexinxinlove/p/3708147.html
多边形重心的求法可参考下面网址
https://www.cnblogs.com/jbelial/archive/2011/08/08/2131165.html
综合上面两个方法可以得出该题的ac代码
代码转自
https://blog.csdn.net/niushuai666/article/details/7454078
ac代码如下
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define INF 0.0000001
const int N = 10010;
struct point
{
double x, y;
point():x(0),y(0){}
}p[N];
int main()
{
int ncase;
scanf("%d", &ncase);
while(ncase--)
{
int n;
double result = 0;
point ans;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%lf%lf", &p[i].x, &p[i].y);
for(int i = 1; i <= n; ++i)
{
double temp = (p[i % n].x * p[i -1].y - p[i % n].y * p[i -1].x) / 2.0;
result += temp;
ans.x += temp * (p[i % n].x + p[i - 1].x) / 3.0;
ans.y += temp * (p[i % n].y + p[i - 1].y) / 3.0;
}
if(fabs(result - 0) < INF)
puts("0.000 0.000");
else
printf("%.3lf %.3lf\n", fabs(result), (ans.x + ans.y) / result); //result取绝对值
}
return 0;
}