SPOJ STONE

From Algorithmist
Jump to navigation Jump to search

40 - Lifting the Stone[edit]

Summary[edit]

You need to find the centre of any general polygon (whether it be regular or irregular one).

Explanation[edit]

This problem is entirely based on formula. The only thing you'll learn here is how you take precision upto k decimal places of a floating value. Formula used can be looked up here - http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

Gotchas[edit]

The main mistake you'll make here is you'll try to take the mean of all the co-ordinates of the input and print it out. That is not center but Centroid of the polygon.


Input[edit]

2
4
5 0
0 5
-5 0
0 -5
4
1 1
11 1
11 11
1 11

Output[edit]

0.00 0.00
6.00 6.00

References[edit]

http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

Categories here, use the form [[Category: Category Name]], see Categories for a list