Lifting the center of gravity of the stone (hdu1115) Polygon

Source: Internet
Author: User
Lifting the stone

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 5370 accepted submission (s): 2239


Problem descriptionthere are eclipsecret openings in the floor which are covered by a big heavy stone. when the stone is lifted up, a special mechanic detects this and activates initialize ONED arrows that are shot near the opening. the only possibility is to lift the stone very slowly and carefully. the ACM team must connect a rope to the stone and then lift it using a pulley. moreover, the stone must be lifted all at once; no side can rise before another. so it is very important to find the center of gravity and connect the rope exactly to that point. the stone has a polygonal shape and its height is the same throughout the whole polygonal area. your task is to find the center of gravity for the given polygon.

 

Inputthe input consists of T test cases. the number of them (t) is given on the first line of the input file. each test case begins with a line containing a single integer N (3 <=n <= 1000000) indicating the number of points that form the polygon. this is followed by n lines, each containing two integers XI and Yi (| Xi |, | Yi | <= 20000 ). these numbers are the coordinates of the I-th point. when we connect the points in the given order, we get a polygon. you may assume that the edges never touch each other (could t the Neighboring ones) and that they never cross. the area of the polygon is never zero, I. e. it cannot collapse into a single line.

 

Outputprint exactly one line for each test case. the line shoshould contain exactly two numbers separated by one space. these numbers are the coordinates of the center of gravity. round the coordinates to the nearest number with exactly two digits after the decimal point (0.005 rounds up to 0.01 ). note that the center of gravity may be outside the polygon, if its shape is not convex. if there is such a case in the input data, print the center anyway.

 

Sample input245 00 5-5 00-541 111 111 11

 

Sample output 0.00 0.006.00 6.00 Question: Find the center of gravity of a polygon ,,,,  Template question.
# Include <stdio. h> # include <stdlib. h>/* ===================================================== ============ * | Returns the center of gravity of a polygon. | init: PNT [] has been sorted clockwise (or counterclockwise); | call: res = bcenter (PNT, N ); \ * =================================================== ============= */struct point {Double X, y;} PNT [1000005], Res; point bcenter (point PNT [], int N) // center of gravity {point P, S; double TP, Area = 0, tpx = 0, TPY = 0; p. X = PNT [0]. x; p. y = PNT [0]. y; For (INT I = 1; I <= N; ++ I) {// point: 0 ~ N-1 S. x = PNT [(I = N )? 0: I]. X; S. Y = PNT [(I = N )? 0: I]. y; TP = (P. x * s. y-s. x * P. y); // area + = TP/2; tpx + = (P. X + S. x) * TP; TPY + = (P. Y + S. y) * TP; p. X = S. x; p. y = S. y;} s. X = tpx/(6 * area); S. y = TPY/(6 * area); Return s ;}Int main () {int t, n, I; scanf ("% d", & T); While (t --) {scanf ("% d", & N ); for (I = 0; I <n; I ++) {scanf ("% lf", & PNT [I]. x, & PNT [I]. y);} res = bcenter (PNT, n); printf ("% 0.2lf % 0.2lf \ n", Res. x, Res. y);} return 0 ;}

 

 

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: info-contact@alibabacloud.com 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.