首页 > 代码库 > poj3855Blast the Enemy!(多边形重心)
poj3855Blast the Enemy!(多边形重心)
链接
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set>10 using namespace std;11 #define N 10000012 #define LL long long13 #define INF 0xfffffff14 const double eps = 1e-8;15 const double pi = acos(-1.0);16 const double inf = ~0u>>2;17 struct point18 {19 double x,y;20 point(double x=0,double y = 0):x(x),y(y){}21 }p[N];22 typedef point pointt;23 point operator -(point a,point b)24 {25 return point(a.x-b.x,a.y-b.y);26 }27 double cross(point a,point b)28 {29 return a.x*b.y-a.y*b.x;30 }31 int main()32 {33 int i,j,n;34 int kk = 0;35 while(scanf("%d",&n)&&n)36 {37 for(i = 0 ; i< n; i++)38 scanf("%lf%lf",&p[i].x,&p[i].y);39 p[n] = p[0];40 double sx = 0,sy = 0,sum =0 ;41 for(i = 1; i < n-1 ;i++)42 {43 double ts = cross(p[i]-p[0],p[i+1]-p[0])/2;44 double x = p[0].x+p[i].x+p[i+1].x;45 double y = p[0].y+p[i].y+p[i+1].y;46 sum+=ts;47 sx+=x*ts;48 sy+=y*ts;49 }50 printf("Stage #%d: %.6f %.6f\n",++kk,sx/3.0/sum,sy/3.0/sum);51 }52 return 0;53 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。