poj3855Blast the Enemy!(多边形重心)

链接

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y = ):x(x),y(y){}
}p[N];
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
int i,j,n;
int kk = ;
while(scanf("%d",&n)&&n)
{
for(i = ; i< n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
p[n] = p[];
double sx = ,sy = ,sum = ;
for(i = ; i < n- ;i++)
{
double ts = cross(p[i]-p[],p[i+]-p[])/;
double x = p[].x+p[i].x+p[i+].x;
double y = p[].y+p[i].y+p[i+].y;
sum+=ts;
sx+=x*ts;
sy+=y*ts;
}
printf("Stage #%d: %.6f %.6f\n",++kk,sx/3.0/sum,sy/3.0/sum);
}
return ;
}
上一篇:Nginx中的root&alias文件路径及索引目录配置详解


下一篇:AngularJS------认识AngularJS