Problem Descriptionthere is x cards on the desk, they is numbered from 1 to X. The score of the card which is numbered I (1<=i<=x) is I. Every round Biebie picks one card out of the X Cards,then puts it back. He does the same operation for B rounds. Assume the score of the j-th card he picks is s j &NBSP;. You is expected to calculate the expectation of the sum of the different score he picks.
Inputmulti Test Cases,the First line of this input is a number T which indicates the number of test cases.in the next T-lines, every line contain x,b separated by exactly one space.
[Technique specification] All numbers is integers. 1<=t<=500000 1<=x<=100000 1<=b<=5
Outputeach case occupies one line. The output format is case #id: ans, here ID is the data number which starts from 1,ans are the expectation, accurate to 3 D Ecimal places. See the sample for more details.
Sample Input22 33 3
Sample outputcase #1:2.625Case #2:4.222
HintFor the first case, all possible combinations Biebie can pick is (1, 1, 1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), 2,2,1 ), (2,2,2) for (1,1,1), there are only one kind number i.e. 1, so the sum of different score are 1.However, for (1,2,1), there IS-kind numbers i.e. 1 and 2, so the sum of different score was 1+2=3.so the sums of different score to corresponding Combination is 1,3,3,3,3,3,3,2so the expectation is (1+3+3+3+3+3+3+2)/8=2.625
Sourcebestcoder Round #26
Test Instructions:
There is a card on the table, each card from 1 to a number, the card numbered I (1<=i<=a) marked with the score I, each time from this a card randomly draw a card, and then put back, perform the B operation, the first card taken out of the score is Sj, What is the expectation of the sum of different kinds of scores after B operation?
Ideas:
Set Xi to indicate whether the card with the score of I is selected in the B operation, Xi=1 is selected, Xi=0 is not selected to the probability that the EX=1*X1+2*X2+3*X3+...+X*XXXI is selected in the B time is n (1-1/x) ^b then E (Xi) = N (1-1/x) ^ B then Ex=1*e (X1) +2*e (X2) +3*e (X3) +...+x*e (Xx) = (1+x) *x/2* (n (1-1/x) ^b)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stdlib.h>6#include <algorithm>7 using namespacestd;8 intMain ()9 {Ten intT; Onescanf"%d",&t); A Doublex,b; - intAc=0; - while(t--) the { -scanf"%LF%LF",&x,&b); - Doubleans=0; - Doublep=1-pow ((1-1.0/x), b); + DoubleNum= (1+X) *x*1.0/2; -ans=num*p; +printf"Case #%d:",++AC); Aprintf"%.3lf\n", ans); at } - return 0; -}View Code
HDU 5159 Card (Expected)