Description
Input
In the next T lines, every line contain x,b separated by exactly one space.
[Technique specification]
All numbers are integers.
1<=T<=500000
1<=x<=100000
1<=b<=5
Output
See the sample for more details.
Sample Input
Sample Output
Hint
For the first case, all possible combinations BieBie can pick are (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 is only one kind number i.e. 1, so the sum of different score is 1. However, for (1,2,1), there are two kind numbers i.e. 1 and 2, so the sum of different score is 1+2=3. So the sums of different score to corresponding combination are 1,3,3,3,3,3,3,2 So the expectation is (1+3+3+3+3+3+3+2)/8=2.625
題意:x張牌,每張牌的值從1到x。依次取b張,注意不是一次性取,即取12和取21是兩種情況。
問所取的牌中值不同的牌的總和的期望爲多少。輸入一組數據t,然後t行,每行一個x一個b。
Hint給出了第一個樣例的解釋,看了就能懂。
題解:首先x張牌依次取b張,因爲每一次取都有x種情況,所以一共會出現x^b種情況,那麼如
果x-1張牌取b張牌就會出現(x-1)^b種情況,所以一張牌會有x^b-(x-1)^b種情況,就是
指有這麼多種情況包含這張牌,而且對於每張牌都是這樣的。那麼這張牌出現的概率爲
(x^b-(x-1)^b)/x^b。由概率求期望的公式可知,這張牌的期望爲這張牌的值乘以這張牌
出現的概率。那麼總期望就爲所有牌的值的和乘以牌出現的概率,因爲每張牌出現的概率
是相同的,所有牌的值的和爲x*(x+1)/2,將每張牌的概率的公式化簡可得1-((1-1/x)^b),
相乘即可,得出最終公式(1-pow(1-1.0/x,b))*x*(x+1)/2。
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { int t,cas=1; double x,b; scanf("%d",&t); while(t--) { scanf("%lf%lf",&x,&b); printf("Case #%d: %.3lf\n",cas++,(1-pow(1-1.0/x,b))*x*(x+1)/2); } return 0; }