题意:求一个不规则简单多边形的重心。
解法:多边形的重心就是所有三角形的重心对面积的加权平均数.
关于求多边形重心的文章:
用叉积搞一搞就行了。
代码:
#include#include #include #include #include #include #define Mod 1000000007#define eps 1e-8using namespace std;struct Point{ double x,y; Point(double x=0, double y=0):x(x),y(y) {} void input() { scanf("%lf%lf",&x,&y); }};typedef Point Vector;int dcmp(double x) { if(x < -eps) return -1; if(x > eps) return 1; return 0;}Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }double CalcConvexArea(Point* p,int n) { //凸包面积 double area = 0.0; for(int i=1;i