首页 > 其他 > 详细

SPOJ Problem 40:Lift the Stone

时间:2015-03-16 22:31:27      阅读:203      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!