Autor Tema: Warmup :: The Birthday Paradox  (Leído 79 veces)

[D-m-K]

  • Administrador
  • Mensajes: 229
  • [-.|.-]
    • MSN Messenger - d4rk.m0nk3y@hotmail.com
    • Ver Perfil
    • Red Informatica Colombiana
    • Email
Warmup :: The Birthday Paradox
« : octubre 18, 2010, 11:14:01 pm »
Este ejercicio si me saco canas jajajajaja, primero porque no entendia la formula correcta que se tenia que aplicar; Luego porque al aplicar el DecimalFormat (para el formateo de la salida de acuerdo al ejercicio) no me arrojaba el punto, entonces investigando un poco mas a fondo se necesitaba usar el DecimalFormatSymbols para definir el caracter usado como separador. Bueno menos charla y mas code ;).

Cita
The Birthday Paradox

Source le name: birthday.c, birthday.cpp or birthday.java

Given n, the number of participants in a birthday party, you have to estimate the probability
that at least one pair of them do have the same birthday (month and day), assuming that a
year has 365 days.
To estimate that probability you may think that the birthday distribution is uniform along
the year, i.e. one person may has been born at any of the 365 days of the year with the same
probability.

Input

Each line of the input contains an integer n (0n365) specifying the number of participants
in the party.
The input must be read from the le birthday.in.

Output

For each case in the input, print one line with the probability that at least one pair of the n
participants do have the same birthday. Round the results to six decimal places. The
oating

point delimiter must be `.' (i.e. the dot). The rounding applies towards the nearest neighbor
unless both neighbors are equidistant, in which case the result is rounded up (e.g. 0:1234562
is rounded to 0:123456; 0:1234566 is rounded to 0:123457; 0:1234565 is rounded to 0:1234567,
etc.).

The output must be written to standard output.

Sample inputOutput for the sample input
365 1.000000
0 0.000000
230.507297

Aqui esta el code ;)

[code=java]
/**
 * Solucion de la paradoja de los cumplea
« Última Modificación: octubre 18, 2010, 11:16:52 pm por [D-m-K] »
:: Todas las grandes cosas que se disfrutan son el producto de las pequeñas cosas que se logran ::