lightOJ 1317 Throwing Balls into the Baskets

10 篇文章 0 订阅
这是一个关于扔球进篮筐游戏的问题,N个人投掷M个篮筐,每轮成功概率为P,总共进行K轮。题目要求计算经过K轮后,投中球的期望数量。给出的样例输入和输出展示了不同情况下的结果。
摘要由CSDN通过智能技术生成

Description

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

题意:

有n个人,m个篮筐,一共打了k轮,每轮每个人可以投一个球,每个球投进的概率都是p,求k轮后,投中的球的期望是多少?

代码实现


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int t,_case=0;
    scanf("%d",&t);
    while(t--)
    {
        int N,M,K;
        double P,ans;
        scanf("%d%d%d%lf",&N,&M,&K,&P);
        ans=double(N)*double(K)*P;
        //cout<<M<<" " <<N<<" " <<K<<" " <<P<<endl;
        printf("Case %d: %.6lf\n",++_case,ans);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值