Page 1 of 2

10439 - Temple of Dune

Posted: Tue Feb 04, 2003 8:59 pm
by Bistromath
I can't figure why i always get WA. I get correct results for sample cases
Is there any special test case with this problem ?

I think my algorithm is good :
1. find the circle through the 3 points
2. find three angles a1, a2, a3 (sorted)
3. compute the gcd( ( a2-1), (a3-a1))
4. result = (2*PI)/gcd

In step 3, i use an epsilon. I have tried many values, without success

Any help appreciated
Thanks

Re: 10439 - Temple of Dune

Posted: Tue Feb 04, 2003 11:28 pm
by gvcormac
Bistromath wrote:I can't figure why i always get WA.

4. result = gcd/(2*PI)

Thanks
Can you prove that result is an integer?

Posted: Wed Feb 05, 2003 12:45 pm
by Andrey Mokhov
By the way their is a nice trick.

In fact you needn't the circle through three points. :wink:

You can get the three angles of the triangle made by the three vertices and then multiply them by 2 - and you will get your a1,a2,a3!! :lol:

So maybe that won't help but it reduces code and floating point errors as there are little floating point operations.

Good luck!
Andrey.

Posted: Wed Feb 05, 2003 4:13 pm
by Bistromath
To gvcormac :

obiously, the gcd i compute is a floating number.
I cast to integer like that :
[cpp]
const double v = GCD( theta1, theta2) ;
const int verticeCount = (int)(0.1 + (2*PI)/v) ;
[/cpp]
I think this is correct

to Andrey :

the angles i need are the angle of the vectors from center of circle to each of the 3 vertices.
i don't see any relation with the 3 angles of the triangles


Thanks for ur help

Posted: Wed Feb 05, 2003 6:29 pm
by gvcormac
Let me rephrase my comment.

Are you sure that v divides 2*PI?

(Hint: it doesn't. This has nothing to do
with floating point representation.)


Bistromath wrote:To gvcormac :

obiously, the gcd i compute is a floating number.
I cast to integer like that :
[cpp]
const double v = GCD( theta1, theta2) ;
const int verticeCount = (int)(0.1 + (2*PI)/v) ;
[/cpp]
I think this is correct

to Andrey :

the angles i need are the angle of the vectors from center of circle to each of the 3 vertices.
i don't see any relation with the 3 angles of the triangles


Thanks for ur help

Posted: Wed Feb 05, 2003 6:53 pm
by Bistromath
I do not understand why v shouldn't divide 2*PI (because we are trying to find a regular polygon).
In all sample cases, 2*PI was a multiple of v (+/- epsilon)

Could u please give some cases where this is not true.

Thanks

Posted: Wed Feb 05, 2003 7:52 pm
by gvcormac
Allow me please to use degrees instead of radians.

Consider a polygon with 360 vertices at integral
angles.

a1 = 0
a2 = 7
a3 = 28

gcd(a2-a1, a3-a1) = 7

7 does not divide 360


Bistromath wrote:I do not understand why v shouldn't divide 2*PI (because we are trying to find a regular polygon).
In all sample cases, 2*PI was a multiple of v (+/- epsilon)

Could u please give some cases where this is not true.

Thanks

Posted: Wed Feb 05, 2003 8:09 pm
by gvcormac
I have given a counterexample.

I would suggest however that you not look at the
counterexample, but instead try to prove that
your assertion below is true.

Often in attempting to prove something you come
up with a counterexample.

Bistromath wrote:I do not understand why v shouldn't divide 2*PI (because we are trying to find a regular polygon).
In all sample cases, 2*PI was a multiple of v (+/- epsilon)

Could u please give some cases where this is not true.

Thanks

Posted: Wed Feb 05, 2003 11:52 pm
by Bistromath
To gvcormac

Thanks for your suggestions, i have finally solved the problem.
As you suggest, GCD is not necessary ( and subject to precision errors) as we now the maximum number of vertices.

Many thanks for your help

Posted: Thu Feb 06, 2003 6:24 am
by cytse
Bistromath wrote:to Andrey :

the angles i need are the angle of the vectors from center of circle to each of the 3 vertices.
i don't see any relation with the 3 angles of the triangles


Thanks for ur help
angle at center == 2 x angle at circumference

Posted: Thu Feb 06, 2003 3:46 pm
by Seokchan
I think my algorithm for this problem is simple and there is no exceptional cases, but I failed to got AC.


My algorithm is :

1. find angles.
2. check whether angles are multiple of (2*Pi/n) (n = 3~200)
(I thought a is multiple of b, if ((a/b) - floor(a/b) < epsilon). )


I wonder my algorithm has some precision problem, but I don`t know how to avoid that problem.

Posted: Thu Feb 06, 2003 4:13 pm
by Bistromath
Seokchan wrote: I wonder my algorithm has some precision problem, but I don`t know how to avoid that problem.
In my accepted solution, i have used the following function to check if a is a multiple of b :


[cpp]
inline bool IsAMultipleOf( double num, double div )
{
const double l = num/div ;
double dl = fabs(l-(int)(l+0.5)) ;
return ( dl < 1E-3 ) ;
}
[/cpp]

Hope this helps

Posted: Thu Feb 06, 2003 4:29 pm
by Seokchan
Thank you :D

I got AC.

Bistromath wrote:
Seokchan wrote: I wonder my algorithm has some precision problem, but I don`t know how to avoid that problem.
In my accepted solution, i have used the following function to check if a is a multiple of b :


[cpp]
inline bool IsAMultipleOf( double num, double div )
{
const double l = num/div ;
double dl = fabs(l-(int)(l+0.5)) ;
return ( dl < 1E-3 ) ;
}
[/cpp]

Hope this helps

are there any method to find out the angles quickly ?

Posted: Fri Feb 07, 2003 12:30 pm
by magicalan
as topic

Posted: Mon Mar 31, 2003 12:27 pm
by Dominik Michniewski
use formula, which compute angle between vectors:

alfa = acos( ABoAC / (sqrt(|AB|) * sqrt(|AC|)) );

ABoAC - scalar multiply of vectors (cross-vector? I don't remember exactly name)
|AC| - length of vector with endings in A and C, similar |AB|

Dominik