Page 1 of 1

### 2410 - Area of Squares

Posted: Sat May 25, 2013 6:14 pm

### Re: 2410 - Area of Squares

Posted: Thu Jun 20, 2013 11:56 pm
Basic geometry knowledge is necessary to solve this.
The length of the edge of the biggest square is given (A1). The length of the next square's edge (A2) can be easily found using PitÃ¡gora's relation:
A2=sqrt( (A1/2)^2 + (A1/2)^2 )=A1/sqrt(2).
Repeating the same reasoning for further minor squares inscribed, it is found that the length of the i_th square's edge (Ai) can be computed as:
Ai=A1/sqrt(2^(i-1)).
The area of the ith square is clearly the length of side squared:
Area_i = Ai^2 = A1^2/2^(i-1)

Pretty simple.

For avoiding machine precision errors, you should use double instead of float variables.
Further machine precision errors can be eluded by adding a small amount to your result, example:

Code: Select all

``const double eps=1e-6;``
This will deal with tricky cases such as:
1/8=0.125000, rounded to %.2lf -> 0.13
for which some compilers would return instead 1/8=0.124999, rounded to %.2lf -> 0.12 == Wrong Answer

### Re: 2410 - Area of Squares

Posted: Tue Jun 25, 2013 11:12 am
A easy problem, with one tricky detail.
Good explanation.
Regards

### Re: 2410 - Area of Squares

Posted: Fri Sep 26, 2014 5:08 pm
muy buena explicacion, gracias por eso

### Re: 2410 - Area of Squares

Posted: Fri Nov 11, 2016 5:57 pm
Hola a todos, comprendo perfectamente la formula dada en el post que explica la solucion, de hecho, habia enviado el resultado antes de consultar aqui, pero, dado el bajo porcentaje de aceptados decidi mirar y me di cuenta de que llego al mismo resultado y obtengo wA, podrian por favor decirme que pasa.
Muchas Gracias.Atentamente
Dimas

### Re: 2410 - Area of Squares

Posted: Mon Nov 14, 2016 11:52 am
DiMas wrote:Hola a todos, comprendo perfectamente la formula dada en el post que explica la solucion, de hecho, habia enviado el resultado antes de consultar aqui, pero, dado el bajo porcentaje de aceptados decidi mirar y me di cuenta de que llego al mismo resultado y obtengo wA, podrian por favor decirme que pasa.
Muchas Gracias.Atentamente
Dimas
``const double eps=1e-6;``