标签:com class div tar get tab ble int table c amp
3 3 0 1 0 2 0 3 3 1 1 0 0 0 1 4 1 1 0 0 0 0.5 0 1
0.000 0.000 0.500 1.000 0.500 1.000
#include<stdio.h>
#include<math.h>
struct point
{
double x,y;
}p[10010];
double getarea(struct point p1,struct point p2)
{
return p1.x*p2.y-p1.y*p2.x;
}
int main()
{
int n,i,T;
double x,y,s,temp;
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]=p[0];
for(i=0,s=x=y=0;i<n;i++)
{
temp=getarea(p[i],p[i+1])/2.0;//各个三角形的有向面积
s+=temp;
x+=temp*(p[i].x+p[i+1].x)/3.0;
y+=temp*(p[i].y+p[i+1].y)/3.0;
}
if(fabs(s-0)<0.0000001)
printf("0.000 0.000\n");
else
printf("%.3lf %.3lf\n",fabs(s),(x+y)/s);
}
return0;
}
标签:com class div tar get tab ble int table c amp
原文地址:http://www.cnblogs.com/52Cyan/p/3698281.html