Throwing Balls into the Baskets LightOJ

来源:互联网 发布:雨露计划app软件 编辑:程序博客网 时间:2024/06/01 09:49

You probably have played the game “Throwing Balls into the Basket”. It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the main game. In our game we were N people trying to throw balls into M identical Baskets. At each turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you will be given the value of N and M. For each player probability of throwing a ball into any basket successfully is P. Assume that there are infinitely many balls and the probability of choosing a basket by any player is 1/M. If multiple people choose a common basket and throw their ball, you can assume that their balls will not conflict, and the probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets after K turns.

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing three integers N (1 ≤ N ≤ 16), M (1 ≤ M ≤ 100) and K (0 ≤ K ≤ 100) and a real number P (0 ≤ P ≤ 1). P contains at most three places after the decimal point.

Output
For each case, print the case number and the expected number of balls. Errors less than 10-6 will be ignored.

Sample Input
2
1 1 1 0.5
1 1 2 0.5
Sample Output
Case 1: 0.5
Case 2: 1.000000

emmmm读了十几遍题目后,按着猜的题意交了一发a了才确定这是个巨sb的水题。
题意:有n个人去投m个篮子,有无限个球,每个人投中球的概率为P,每一轮每个人都选择一个球投一次,投向同一个篮筐的球互不影响。问经过k轮后的进球数量的期望是多少

思路:一轮进球的数量期望为n*p,k轮即为n*p*k。(所以那m个篮筐是干啥用的?。。。)
代码如下

#include<bits/stdc++.h>using namespace std;#define LL long long int main(){    int T;    scanf("%d",&T);    for(int cas=1;cas<=T;cas++)    {        int N,M,K;        double P;        scanf("%d%d%d%lf",&N,&M,&K,&P);        printf("Case %d: %.7lf\n",cas,N*K*P);     }    return 0;}