Loading editor...
The center of gravity
Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2423 accepted submission (s): 1324
Problem descriptioneveryone know the story that how Newton discovered the Universal Gravitation. One day, Newton received
Leisurely, suddenly, an apple hit his head. Then Newton discovered the Universal Gravitation. From then
On, people have sovled into problems by 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?
Inputthe 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.
Outputfor each case, print the coordinate, accurate up to 1 decimal places.
Sample input2
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 output3.0 2.7
2.0 2.3
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int main( )
6 {
7 int N;
8 while(scanf("%d", &N), N) {
9 double x1,x2,y1, y2,x3,y3;
10 while (N--)
11 {
12 scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1, &x2, &y2,&x3,&y3);
13 printf("%.1lf %.1lf", (x1 + x2 + x3)/ 3, (y1 + y2 + y3)/3);
14 puts("");
15 }
16 }
17 return 0;
18 }