把每个三角形看成一个质点,坐标就是各自的重心,
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100+10,maxn=500+100,inf=0x3f3f3f; struct point{ double x,y; /* point(){}; point(double _x,double _y):x(_x),y(_y){} point operator *(double p) { return point(x*p,y*p); } double operator *(point p) { return x*p.x+y*p.y; } point operator /(double p) { return point(x/p,y/p); } point operator +(point p) { return point(x+p.x,y+p.y); } point operator -(point p) { return point(x-p.x,y-p.y); }*/ }; point p[N],s[N]; int n; inline bool zero(double x) { return fabs(x)<eps; } double dir(point p1,point p2,point p3) { return (p3.x-p1.x)*(p2.y-p1.y)-(p3.y-p1.y)*(p2.x-p1.x); } double dis(point p1,point p2) { return sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); } bool comp(point p1,point p2) { double te=dir(p[0],p1,p2); if(te<0)return 1; if(zero(te)&&dis(p[0],p1)<dis(p[0],p2))return 1; return 0; } void Graham() { for(int i=1;i<n;i++) if(p[i].x<p[0].x||(p[i].x==p[0].x&&p[i].y<p[0].y)) swap(p[0],p[i]); sort(p+1,p+n,comp); p[n]=p[0]; s[0]=p[0],s[1]=p[1],s[2]=p[2]; int top=2; for(int i=3;i<=n;i++) { while(top>=2&&dir(s[top-1],s[top],p[i])>=0)top--; s[++top]=p[i]; } // for(int i=0;i<top;i++)cout<<s[i].x<<" "<<s[i].y<<endl; point ans; ans.x=0.0;ans.y=0.0; double sum=0; for(int i=2;i<top;i++) { double te=dir(s[0],s[i],s[i-1]); sum+=te; ans.x+=(s[0].x+s[i].x+s[i-1].x)/3*te; ans.y+=(s[0].y+s[i].y+s[i-1].y)/3*te; } ans.x=ans.x/sum;ans.y=ans.y/sum; if(zero(ans.x))ans.x=0.0;if(zero(ans.y))ans.y=0.0; cout<<ans.x<<" "<<ans.y<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout<<setiosflags(ios::fixed)<<setprecision(3); while(cin>>n){ if(n<3)continue; for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y; Graham(); } return 0; } /********************* 4 0 1 1 1 0 0 1 0 3 1 2 1 0 0 0 7 -4 -4 -6 -3 -4 -10 -7 -12 -9 -8 -3 -6 -8 -3 1 *********************/