
10002 - Center of Masses
Moderator: Board moderators
cross-product result may exceeds INT range

I think I will help you, as I've got Accepted.
The algorithm consists of three parts.
Lets take vertix 1, where 1 is the vertix with minimal y coorinate.
Sort all the verticies by value of arctan(tha angle bitween the line connecting verticies i and 1 and x axis).
So we will find the convex hull.
Divide the polygon ito n - 2 triangles.
Put points in the centres of that triangles with eight equal to the sqare of that triangle.
Find the centre of n - 2 points.
That's all.
Lets take vertix 1, where 1 is the vertix with minimal y coorinate.
Sort all the verticies by value of arctan(tha angle bitween the line connecting verticies i and 1 and x axis).
So we will find the convex hull.
Divide the polygon ito n - 2 triangles.
Put points in the centres of that triangles with eight equal to the sqare of that triangle.
Find the centre of n - 2 points.
That's all.
:)
Try this data 
Input :
4
19999999999 1
1 3
3 1
1 2
1
Output :
6666666667.333 1.667

Input :
4
19999999999 1
1 3
3 1
1 2
1
Output :
6666666667.333 1.667
-
- New poster
- Posts: 13
- Joined: Tue Aug 03, 2004 4:24 am
- Location: CHINA
10002 WA
I use formula below,why WA?Thanks in advance!


-
- New poster
- Posts: 28
- Joined: Tue Aug 03, 2004 8:11 pm
- Contact:
10002 - Get WA
HELP ....
I get WA! my cases (i wanna + cases in AC program plix)
4
1 1
1 3
3 1
1 2
4
19999999999 1
1 3
3 1
1 2
out put
1.667 1.667
6666666667.333 1.667
I get WA! my cases (i wanna + cases in AC program plix)
4
1 1
1 3
3 1
1 2
4
19999999999 1
1 3
3 1
1 2
out put
1.667 1.667
6666666667.333 1.667
-
- New poster
- Posts: 28
- Joined: Tue Aug 03, 2004 8:11 pm
- Contact:
10002

i find my problem try
4
1 1
-1 -1
-1 1
1 -1
see if your answer is
-0.000 -0.000 // no good
good lock.
10002 - Centre of Masses
Hi!
Could anybody explian me how to sort these points? Is there any efficent algo for that?
Could anybody explian me how to sort these points? Is there any efficent algo for that?
Isn't the center of masses simply the point
(Cx,Cy) where
Cx = ( Sum ( x , i = 0,1,..,N ) ) DIV N;
Cy = ( Sum ( y , i = 0,1,..,N ) ) DIV N;
By DIV I mean normal division floating point division.
That was my impression for center of masses.
What are the formulas you are giving above?
Can you point me to some source which defines the
"term" center of masses differently that I do.
What is strange is that for the test case:
7
-4 -4
-6 -3
-4 -10
-7 -12
-9 -8
-3 -6
-8 -3
I get answer:
-5.857 -6.571
which is far away from
-6.102 -7.089
and that is the answer shown on the problem page:
http://acm.uva.es/p/v100/10002.html
(Cx,Cy) where
Cx = ( Sum ( x , i = 0,1,..,N ) ) DIV N;
Cy = ( Sum ( y , i = 0,1,..,N ) ) DIV N;
By DIV I mean normal division floating point division.
That was my impression for center of masses.
What are the formulas you are giving above?
Can you point me to some source which defines the
"term" center of masses differently that I do.
What is strange is that for the test case:
7
-4 -4
-6 -3
-4 -10
-7 -12
-9 -8
-3 -6
-8 -3
I get answer:
-5.857 -6.571
which is far away from
-6.102 -7.089
and that is the answer shown on the problem page:
http://acm.uva.es/p/v100/10002.html
By the way even using your formulas I can not
get the answer that the author of the problem has given
for the test case:
7
-4 -4
-6 -3
-4 -10
-7 -12
-9 -8
-3 -6
-8 -3
Obviously
1) either the author of the problem has a different idea about
center of masses
OR
2) there is some small mistake in your formulas.
What do you think ?
If someone has managed to solve the problem let's just
give us the right formulas for
Cx and Cy.
get the answer that the author of the problem has given
for the test case:
7
-4 -4
-6 -3
-4 -10
-7 -12
-9 -8
-3 -6
-8 -3
Obviously
1) either the author of the problem has a different idea about
center of masses
OR
2) there is some small mistake in your formulas.
What do you think ?
If someone has managed to solve the problem let's just
give us the right formulas for
Cx and Cy.
more info ?!
"check the old posts and it should give you an idea"
Should give me an idea about what ? About the correct formulas
for Cx and Cy or ... ? Well, I think I've been looking in all threads
in the forum dedicated to problem 10002 and the above
given formulas are the only thing I've found.
Just give me some links pls if it is not much trouble for you.
Apart from this THANKS for the remark that the input can contain
also floating point numbers, that is precious.
Thank you.
Should give me an idea about what ? About the correct formulas
for Cx and Cy or ... ? Well, I think I've been looking in all threads
in the forum dedicated to problem 10002 and the above
given formulas are the only thing I've found.
Just give me some links pls if it is not much trouble for you.
Apart from this THANKS for the remark that the input can contain
also floating point numbers, that is precious.
Thank you.
10153EN wrote:I think your definition of centre of mass is not correct for all case, just correct for triangles.
I sure think that these posts give enough hints... If you don't understand the concept why don't you just keep away from this problem?Maarten wrote:Btw, the definition of "Center of mass" is quite easy: Suppose you make the polygon out of wood (make it massive), and try to balance it on the tip of your finger. The center of mass is the single point where it will not fall off your finger.
I think many people here are confused with the center of mass of a number of mass points. If you apply the formulas mentioned above, what you are really calculating is the center of mass in the case that all mass of the polygon is concentrated around the vertices (with each vertex having equal mass). However, in this problem the mass is distributed equally on the polygon.
If you still want to apply the "simple formula" for the center of mass, you can consider the massive polygon as a large number of mass points distributed equally on the polygon. But to get the correct answer, you will have to take the limit in which the number of points goes to infinity, and then your sum becomes an integral.

7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Sedefcho,
I dont mean this threat, hahaha
There's another threat with 2 pages of reply, and the first post of that threat pretty much give you the code for the calculation.
In fact,
http://online-judge.uva.es/board/viewto ... ight=10002
is what I was refering to.
I dont mean this threat, hahaha
There's another threat with 2 pages of reply, and the first post of that threat pretty much give you the code for the calculation.
In fact,
http://online-judge.uva.es/board/viewto ... ight=10002
is what I was refering to.