Set N discrete data points (xi, yi) (I = 1, 2,., n) on the plane.
Polygon center of gravity G (. x1,. y1) is:
Sum:
# Include <iostream> # include <algorithm> # include <cstring> # include <cstdio> using namespace std; struct Point {double x, y ;}; // calculate the Area double Area (const Point p0, const Point p1, const Point p2) using cross product {// In addition, you do not need to consider whether the point input sequence is clockwise or counterclockwise. After division, it is offset. Return (p0.x * p1.y + p1.x * p2.y + p2.x * p0.y-p1.x * p0.y-p2.x * p1.y-p0.x * p2.y)/2.0;} int main () {int T, n; scanf ("% d", & T); while (T --) {Point p0, p1, p2; double area = 0, suma = 0, sumx = 0, sumy = 0; scanf ("% d", & n); scanf ("% lf", & p0.x, & p0.y); scanf ("% lf ", & p1.x, & p1.y); for (int I = 2; I <n; ++ I) {scanf ("% lf", & p2.x, & p2.y ); area = Area (p0, p1, p2); suma + = area; sumx + = (p0.x + p1.x + p2.x) * area; sumy + = (p0.y + p1.y + p2.y) * area; p1 = p2;} printf ("%. 2lf %. 2lf \ n ", sumx/suma/3, sumy/suma/3);} return 0 ;}
Zookeeper