付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0
# include<iostream>
# include
<algorithm>
using namespace std;
const int maxNum = 1000000 +2;
struct point { double x, y; };
struct point data[maxNum];
struct point bcenter(struct 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) { // point: 0 ~ n-1
        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 T,i,j,num;
    
struct point re;
    scanf(
"%d",&T);
    
while(T--)
    {
        scanf(
"%d",&num);
        
for(i = 0; i < num ; i ++)
            scanf(
"%lf %lf",&data[i].x,&data[i].y);
        
//sort(data,data+num);
        re = bcenter(data,num);
        printf(
"%.2lf %.2lf\n",re.x,re.y);
    }
    
return 0;
}

posted on 2010-07-28 12:55 付翔 阅读(629) 评论(2)  编辑 收藏 引用 所属分类: ACM 数据结构

FeedBack:
# re: hdu 1115 Lifting the Stone 计算几何 求多边形的重心
2010-09-03 16:31 | lanya
不要考虑四舍五入吗?  回复  更多评论
  
# re: hdu 1115 Lifting the Stone 计算几何 求多边形的重心
2010-09-14 17:05 | 付翔
@lanya
.2lf 会进行舍入 题目是保存两位有效数字   回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年7月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜