首页 > 其他 > 详细

poj3855Blast the Enemy!(多边形重心)

时间:2014-08-15 14:27:08      阅读:285      评论:0      收藏:0      [点我收藏+]

链接

bubuko.com,布布扣
 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 100000
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 struct point
18 {
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 }
View Code

 

poj3855Blast the Enemy!(多边形重心),布布扣,bubuko.com

poj3855Blast the Enemy!(多边形重心)

原文:http://www.cnblogs.com/shangyu/p/3914685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!