Card Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 975 Accepted Submission (s): 425
Special Judge
Problem Description There 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.
Input Multi Test cases,the first line of the 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
Output each 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 Input
2 2 3) 3 3
Sample Output
Case #1:2.625 case #2:4.222 Hint for 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-one kind number i.e. 1, so the sum of different SCO Re is 1. However, for (1,2,1), there was, 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 be 1,3,3,3,3,3,3,2 so the expectation is (1+3+3+3+3+3+3+2)/8= 2.625 Test Instructions: X card, the value of each card from 1 to X. Take b in turn, note is not a one-time fetch, that is, take 12 and take 21 is two cases. Ask how much you expect from the sum of the different cards in the card you take. Enter a set of data T, then T line, one x per line, and one B. Hint gave the first example of the explanation, read it can understand.
Puzzle: First x cards in turn take B, because every time there are X cases, so there will be a total of x^b, then if the x-1 card take B card will appear (x-1) ^b, so a card will have x^b-(x-1) ^b kind of situation, that is, there are so many circumstances including this card, And this is the case for every card. Then the probability of this card appearing is (x^b-(x-1) ^b)/x^b. The desired formula of probability indicates that the card's expectation is multiplied by the probability of the card appearing. Then total expectations for the value of all cards and multiplied by the probability of the card, because each card appears the probability is the same, the value of all the cards and for x* (x+1)/2, the probability of each card formulation can be reduced to 1-((1-1/x) ^b), multiply can be reached, the final formula (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;
}