Topic links
Test instructions
Give a homogeneous n of the dice, to throw out all points at least once the expected number of times.
Ideas:
This is a classic stamp collection issue (Coupon Collector problem).
The probability of throwing out the first non-appearing point is n/n = 1, because the first throw must not appear.
The second non-occurrence of the first occurrence of a point is the probability of (n-1)/n, because there is a throw has already appeared.
The first occurrence of the No. I non-appearing points is the probability of (n-i)/I, which satisfies the geometric distribution.
Its expectation e = 1/p
So expect for n * (1 + 1/2 + 1/3 + ... 1/n).
Code:
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <ctime>6#include <Set>7#include <map>8#include <list>9#include <queue>Ten#include <string> One#include <vector> A#include <fstream> -#include <iterator> -#include <iostream> the#include <algorithm> - using namespacestd; - #defineLL Long Long - #defineINF 0x3f3f3f3f + #defineMOD 1000000007 - #defineEPS 1e-6 + #defineMAXN 100010 A #defineYY 0.5772156649 at DoubleF[MAXN]; - voidInit () - { -f[0] =0.0; - for(inti =1; i < MAXN; i + +) -F[i] = f[i-1] +1.0/(I *1.0); in } - DoubleGetexpectation (intN) to { + returnn *1.0*F[n]; - } the * intMain () $ {Panax Notoginseng intT; - intKcase =0; the init (); +scanf"%d", &T); A while(T--) the { + intN; -scanf"%d", &n); $printf"Case %d:%.7lf\n", ++kcase, Getexpectation (n)); $ } - return 0; -}View Code
lightoj_1248 Dice (III)