## 11189 - A Simple Pendulum

Moderator: Board moderators

cytmike
Learning poster
Posts: 95
Joined: Mon Apr 26, 2004 1:23 pm
Location: Hong Kong and United States
Contact:

### 11189 - A Simple Pendulum

Can anybody offer some hint?
Impossible is Nothing.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
Compute coordinates of G (center of masses), and distance from it to point A from formulas in the problem statement.
Find points of intersection of circle of radius AG and center in G with the polygon.

pineapple
Learning poster
Posts: 57
Joined: Fri Nov 03, 2006 3:33 pm
I always get WA.Could anyone who have got AC post some critical cases for me.I used the following algorithm to count d:
for each line segment p1p2, first calculate d1=|Cp1|,d2=|Cp2|.C is the center of the quadrilateral.
1) if((AG>d1&&AG<d2)||(AG<d1&&AG>d2)) then d=d+1
2) else if(AG<d1&&AG<d2)
check whether there are two intersecting point:
assume CI plumb p1p2 calculate the coordinate of I.
if(I is a point of p1p2&&CI<AG) then d=d+2
else d=d+0
3) else d=d+0;

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan
How did you calculate the center of the quadrilateral ?

pineapple
Learning poster
Posts: 57
Joined: Fri Nov 03, 2006 3:33 pm
I used the following algorithm:

Code: Select all

``````Cut off
``````
Is it right?I think it needn't swap the point.
Last edited by pineapple on Wed Mar 07, 2007 3:57 pm, edited 2 times in total.

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan
Here is a case that your code doesn't work. Consider this quadrilateral.

Code: Select all

``````1 0 2 0 1 1 0 1
``````
The Center of this quadrilateral must be

Code: Select all

``````Center(x, y) = (1.000, 0.500)
``````

Code: Select all

``````Center(x, y) = (0.777, 0.444)
``````

pineapple
Learning poster
Posts: 57
Joined: Fri Nov 03, 2006 3:33 pm
Yes,I made a silly mistake in my previous code,but actual I have corrected it about 2 hours ago.This must be right.But I also get WA.

Code: Select all

``````Cut off
``````

pineapple
Learning poster
Posts: 57
Joined: Fri Nov 03, 2006 3:33 pm
Very strange.When I only change

Code: Select all

``````struct point
{
int x,y
}
``````
to

Code: Select all

``````struct point
{
double x,y
}
``````
and get AC.
other variables' type I used are all double expect i and d.
So I think it should be still feasible.Actually,Other parts are all OK.But WA!However,Thanks for your great help.
By the way,could you tell me why your code is so efficient that runs only 0.006S,actually I know some of problems you have solved are also very nice,the rank is quite high.Could you share it with me?