Card
Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 191 Accepted Submission (s): 52
Special Judge
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 SJ . 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 was 1,3,3,3,3,3,3,2so the expectation is (1+3+3+3+3+3+3+2)/8=2.625 It's my practice to think of it as an M-layer X-fork tree (with x^b at the bottom) Leaf node), and then calculate the number of times each number (1~X) is added. for (i = 1 ~ x): will add x^ (m-1) on the 1th floor. 2nd floor will add x^ (m-2) * (x-1) times. .... Layer I will add x^ (m-i) * (x-1) ^ (i-1). .... The level m will be added x^ (0) * (x-1) ^ (m-1) times. Take I = 1 as an example, such as: then the number of times per addition is x^i * (x-1) ^ (m-i-1) times [0 <= i < m]. Total Plus sum = Sigma (j) * x^i * (x-1) ^ (m-i-1) times [1<=j <= x, 0 <= i < m]. Sigma (j) [1<=j <= x ] = (1+x) *x/2. Then sum = (1+x) * x/2 * x^i * (x-1) ^ (m-i-1), [ 0 <= i < m]. so expect Ex = sum/(x ^ n). The official solution is to give common use probability method:
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)
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>#include<algorithm>using namespacestd;#defineRoot 1,n,1#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1#defineLR rt<<1#defineRR rt<<1|1typedefLong LongLl;typedef pair<int,int>PII;#defineX First#defineY SecondConst intOO = 1e9+7;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6 ;Const intN =100010;Doublen;intm;voidRun () {scanf ("%lf%d",&n,&m); DoubleAvg = (1.0+ N) * N/2.0* POW (1.0/N, (Double) m), res =0 ; for(inti =0; I < m; ++i) {res+ = avg * POW (N-1.0, (Double) i) *pow ((Double) N, m-i-1.0 ); } printf ("%.3lf\n", res);}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); #endif //LOCALIos::sync_with_stdio (false); int_, cas =1; scanf"%d",&_); while( _--) {printf ("Case #%d:", cas++); Run (); }}
View Code
HDU 5159 Card (Counting Period Hope)