hdu 2015 The Center of Gravity
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
重心
問題描述
大家都知道牛頓發(fā)現(xiàn)萬(wàn)有引力的故事。有一天,牛頓悠閑地走路,突然,一個(gè)蘋果擊中了他的頭。然后牛頓發(fā)現(xiàn)了萬(wàn)有引力。到目前為止,人們已經(jīng)用萬(wàn)有引力理論解決了許多問題。更重要的是,我也都知道每個(gè)物體都有重心。現(xiàn)在,你已經(jīng)得到了三角形中三個(gè)點(diǎn)的坐標(biāo)。你能算出中心嗎,三角形的重力?
輸入
第一行是一個(gè)整數(shù)n,這是測(cè)試用例的數(shù)量。
然后是n行。每條直線有6個(gè)數(shù)字x1,y1,x2,y2,x3,y3,這是三個(gè)點(diǎn)的坐標(biāo)。
輸入在n = 0時(shí)終止。
輸出
對(duì)于每種情況,打印坐標(biāo),精確到小數(shù)點(diǎn)后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;
}
