lightoj_1248 Dice (III)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.