hdu 2015 The Center of Gravity

ACM比赛整理

共 1851字,需浏览 4分钟

 ·

2021-09-12 16:42

The Center of Gravity

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8255    Accepted Submission(s): 4737


Problem Description

Everyone know the story that how Newton discovered the Universal Gravitation. One day, Newton walked
leisurely, suddenly, an apple hit his head. Then Newton discovered the Universal Gravitation.From then
on,people have sovled many problems by the the theory of the Universal Gravitation. What's more, wo also
have known every object has its Center of Gravity.
Now,you have been given the coordinates of three points of a triangle. Can you calculate the center
of gravity of the triangle?

 


Input

The first line is an integer n,which is the number of test cases.
Then n lines follow. Each line has 6 numbers x1,y1,x2,y2,x3,y3,which are the coordinates of three points.
The input is terminated by n = 0.

 


Output

For each case, print the coordinate, accurate up to 1 decimal places.

 


Sample Input

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

 


Sample Output

3.0 2.7
2.0 2.3


重心

问题描述


大家都知道牛顿发现万有引力的故事。有一天,牛顿悠闲地走路,突然,一个苹果击中了他的头。然后牛顿发现了万有引力。到目前为止,人们已经用万有引力理论解决了许多问题。更重要的是,我也都知道每个物体都有重心。现在,你已经得到了三角形中三个点的坐标。你能算出中心吗,三角形的重力?


输入


第一行是一个整数n,这是测试用例的数量。

然后是n行。每条直线有6个数字x1,y1,x2,y2,x3,y3,这是三个点的坐标。

输入在n = 0时终止。


输出

对于每种情况,打印坐标,精确到小数点后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 <stdio.h>
int main()
{
double a,b,c,d,e,f;
int t;
while(scanf("%d",&t)!=EOF&&t!=0)
{
while(t--)
{
scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
printf("%.1lf %.1lf\n",(a+c+e)/3.0,(b+d+f)/3.0);
}
}
return 0;
}


浏览 20
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报