题意 裸的计算几何 求多边形重心;
#include<iostream> #include<stdio.h> #include<cstring> #include<algorithm> #include<cmath> using namespace std; double a,b,c,d,e,f; double mix( double x,double y,double xx,double yy ){return x*yy - xx*y;} int main( ) { int N,T; scanf("%d",&T); while( T-- ) { scanf("%d",&N); scanf("%lf%lf%lf%lf",&a,&b,&c,&d); double sumx = 0,sumy = 0,suma = 0; for( int i = 3; i <= N; i++ ) { scanf("%lf%lf",&e,&f); double area = mix(e-a,f-b,c-a,d-b)/2.0; sumx += (( a+c+e )*area); sumy += (( b+d+f )*area); suma += area; c = e; d = f; } sumx = int(sumx/suma/3.0*100000.0); sumy = int(sumy/suma/3.0*100000.0); printf("%.2lf %.2lf ",sumx/100000.0,sumy/100000.0); } return 0; }