问题 A: 重心在哪里

xiaoxiao2021-03-01  14

题目描述

每个人都知道牛顿发现万有引力的故事。自从牛顿发现万有引力后,人们用万有引力理论解决了非常多的问题。不仅如此,我们也知道了每个物体都有自己的重心。 现在,给你三角形三个顶点的坐标,你能计算出三角形的重心吗?

输入

题目包含多组测试数据。第一行输入一个正整数n,表示测试数据的个数,当n=0时,输入结束。 接下来n行,每行包含6个数字x1,y1,x2,y2,x3,y3,表示三角形三个顶点的坐标。

输出

对于每组输入,输出重心的坐标,结果保留1位小数。

样例输入

2 1.0 2.0 3.0 4.0 5.0 2.0 1.0 1.0 4.0 1.0 1.0 5.0 0

样例输出

3.0 2.7 2.0 2.3

 

#include <cstdio> #include <utility> using namespace std; int main(){ pair<double,double> s[3]; int n; while(scanf("%d",&n)){ if(n==0) break; for(int i=0;i<n;i++){ pair<double,double> x(0,0); for(int j=0;j<3;j++){ scanf("%lf%lf",&s[j].first ,&s[j].second ); x.first+=s[j].first ; x.second+=s[j].second ; } printf("%.1f %.1f\n",x.first/3,x.second/3); } } return 0; }

 

转载请注明原文地址: https://www.6miu.com/read-3849928.html

最新回复(0)