#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> struct Point{ double x; double y; }point[10010]; int i,n,m; int main() { scanf("%d",&n); while(n--){ scanf("%d",&m); double tmp,area=0,x=0,y=0; for(i=0;i<m;i++) scanf("%lf%lf",&point[i].x,&point[i].y); for(i=1;i<=m;i++){ tmp=(point[i%m].x*point[i-1].y-point[i-1].x*point[i%m].y)/2.0; area+=tmp; x+=tmp*(point[i%m].x+point[i-1].x)/3.0; y+=tmp*(point[i%m].y+point[i-1].y)/3.0; } if(fabs(area-0)<0.0000001) puts("0.000 0.000"); else printf("%.3lf %.3lf\n",fabs(area),(x+y)/area); } //system("pause"); return 0; }
精度要求很高,把变量定义成float都不行,贡献了好几个WA!