acm--Triangle Center of Gravity--hdoj 2105--the center of gravity--Water

Source: Internet
Author: User

Hdoj Title Address: Portal

The Center of GravityTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 5570 Accepted Submission (s): 3179

Problem Descriptioneveryone know the story of how Newton discovered the Universal gravitation. One day, Newton walked
Leisurely, suddenly, an Apple hits his head. Then Newton discovered the Universal Gravitation.from then
On,people has sovled many problems by the the theory of the Universal gravitation. What's more, Wo Also
There are known every object with its Center of Gravity.
Now,you has been given the coordinates of three points of a triangle. Can you calculate the center
of gravity of the triangle?
Inputthe first line is a 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 is the coordinates of three points.
The input is terminated by n = 0.
Outputfor, print the coordinate, accurate up to 1 decimal places.
Sample Input
21.0 2.0 3.0 4.0 5.0 2.01.0 1.0 4.0 1.0 1.0 5.00

Sample Output
3.0 2.72.0 2.3

#include <iostream> #include <stdio.h>using namespace Std;int main () {    int n;    while (scanf ("%d", &n) &&n) {         double x1,x2,x3,y1,y2,y3;        while (n--) {            cin>>x1>>y1>>x2>>y2>>x3>>y3;            printf ("%.1lf%.1lf\n", (X1+X2+X3)/3, (Y1+Y2+Y3)/3);}}}    

acm--Triangle Center of Gravity--hdoj 2105--the center of gravity--Water

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.