HDU 2105 The Center of Gravity

来源:互联网 发布:xlwt与python 编辑:程序博客网 时间:2024/05/17 05:57

利用重心的特点 设 A(x1,y1)       B(x2,y2)     C(x3,y3)

 BC的中点D 重心为点O,可知 D的坐标      [(x2+x3)/2,(y2+y3)/2]

 利用0A=2OD 得:     0x= (Dx-Ax)*2/3 + Ax                Oy=(Dy-Ay)*2/3 +Ay

#include<stdio.h>
int main()
{
 double x,y,x1,y1,x2,y2,x3,y3;
 int t;
 while(scanf("%d",&t)!=EOF && t)
 {
     while(t--){
      scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3); 
      x=(x1+x2)/2;
   y=(y1+y2)/2;
   x=(x-x3)*2/3+x3;
   y=(y-y3)*2/3+y3;
   printf("%.1lf %.1lf\n",x,y);
  } 
 }
    return 0; 
}

原创粉丝点击