hdu 1115 Lifting the Stone 多边形的重心

 

#include<iostream>
#include
<cmath>
using namespace std;
struct point{
double x,y;
point (
double xx=0,double yy=0){
x
=xx; y=yy;
}
double operator *(point b){
return x*b.y-y*b.x;
}
}p[
1000001];
int main()
{
int T,N,i;
scanf(
"%d",&T);
while(T--)
{
scanf(
"%d",&N);
for(i=0;i<N;i++)
scanf(
"%lf%lf",&p[i].x,&p[i].y);
p[N].x
=p[0].x; p[N].y=p[0].y;
double area=0;
point re;
for(i=0;i<N;i++)
{
area
+=p[i]*p[i+1];
re.x
+=(p[i].x + p[i+1].x)* (p[i]*p[i+1]);
re.y
+=(p[i].y + p[i+1].y)* (p[i]*p[i+1]);
}
area
/=2;
re.x
/= 6*area;
re.y
/= 6*area;
printf(
"%.2lf %.2lf\n",re.x,re.y);
}
return 0;
}

 

posted @ 2010-08-28 21:27  孟起  阅读(202)  评论(0编辑  收藏  举报