码迷,mamicode.com
首页 > 其他好文 > 详细

SPOJ Problem 40:Lift the Stone

时间:2015-03-16 22:31:38      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

求多边形的重心。。

啥都不说了,代公式。。

#include<cstdio>
double x0,y0,x1,y1,x2,y2,s,as,gx,gy;
int t,n;
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        scanf("%lf%lf",&x0,&y0);
        scanf("%lf%lf",&x1,&y1);
        s=gx=gy=0;n-=2;
        while(n--){
            scanf("%lf%lf",&x2,&y2);
            as=(x1*y2+x0*y1+x2*y0-x1*y0-x0*y2-x2*y1)/2;
            s+=as;
            gx+=(x0+x1+x2)*as;x1=x2;
            gy+=(y0+y1+y2)*as;y1=y2;    
        }
        printf("%.2lf %.2lf\n",gx/s/3,gy/s/3);
    }
}

 

SPOJ Problem 40:Lift the Stone

标签:

原文地址:http://www.cnblogs.com/moris/p/4342869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!