设为首页 加入收藏

TOP

hdu1115 Lifting the Stone(几何,求多边形重心模板题)
2015-11-21 01:00:13 来源: 作者: 【 】 浏览:2
Tags:hdu1115 Lifting the Stone 几何 多边形 重心 模板

题意:就是给你一个多边行的点的坐标,求此多边形的重心。

一道求多边形重心的模板题!

?

#include
  
   
#include
   
     #include
    
      using namespace std; struct point { double x,y; }PP[1000047]; point bcenter(point pnt[],int n){ point p,s; double tp,area = 0, tpx=0, tpy=0; p.x=pnt[0].x; p.y=pnt[0].y; for(int i=1;i<=n;++i){ s.x=pnt[(i==n)?0:i].x; s.y=pnt[(i==n)?0:i].y; tp=(p.x*s.y-s.x*p.y); area += tp/2; tpx += (p.x + s.x) * tp; tpy += (p.y + s.y) * tp; p.x = s.x; p.y = s.y; } s.x=tpx / (6*area);s.y=tpy/(6*area); return s; } int main() { int N,t; scanf("%d",&t); while(t--){ scanf("%d",&N); for(int i=0;i
     
      

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ STL set常用函数大全 下一篇hdu 1374 求三角形外接圆的半径

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: