题目大意: 让你输入一个n边形的n个点的坐标,要你求这个多边形的重心。 解题思路: 用叉积的思想把多边形给分割成多个小三角形,就可以搞定啦。 贴公式:C=sigma(Ai * Ci) / A (i=1…N) Ci=Centroid(△ O Pi Pi+1) = (O + ↑Pi +↑Pi+1 )/3 C=sigma( (↑Pi +↑Pi+1) (↑Pi ×↑Pi+1) ) /(6A) 代码:
#include
using namespace std;
const int MAX=1000005;
typedef struct point
{
	double x;
	double y;
	point(double a=0,double b=0) :x(a),y(b) {}
	double operator *(point b)
	{
		return x*b.y-y*b.x;
	}
}P;

int n;
P po[MAX];
double cen_x,cen_y;
void centerGra()//可算凹凸多边形
{
	double area=0;
	for(int i=0;i>cas;
	while(cas--)
	{
		cen_x=cen_y=0;
		cin>>n;
		for(i=0;i>po[i].x>>po[i].y;
		centerGra();
		printf("%.2lf %.2lf\n",cen_x,cen_y);
	}
	return 0;
}

posted on 2011-11-06 13:04  cchun  阅读(167)  评论(0编辑  收藏  举报