lightOJ 1317 Throwing Balls into the Baskets

lightOJ  1317  Throwing Balls into the Baskets(期望)  解题报告

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/A

题目:

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轮后,投中的球的期望是多少?

分析:

因为每个人投进的概率都是相同的,所以期望也是相同的。因此只需要求出第一轮的期望就可以了,总期望=k*第一轮的期望。

代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4
 5 int t,n,m,k;
 6 double p,ans;
 7 int a[20][20];
 8
 9 void init()
10 {
11     a[1][1]=1;
12     a[1][0]=1;
13     for(int i=2;i<20;i++)
14     {
15         a[i][i]=1;
16         a[i][0]=1;
17         for(int j=1;j<i;j++)
18             a[i][j]=a[i-1][j]+a[i-1][j-1];
19     }
20 }
21
22 double count(int j)
23 {
24     double b=1.0;
25     for(int i=0;i<j;i++)
26         b=b*p;//投中的期望
27     for(int i=0;i<n-j;i++)
28         b=b*(1.0-p);//没投中的期望
29     return b*j*a[n][j];
30 }
31
32 int main()
33 {
34     int c=1;
35     scanf("%d",&t);
36     init();
37     while(t--)
38     {
39         scanf("%d%d%d%lf",&n,&m,&k,&p);
40         ans=0.0;//小数
41         for(int i=0;i<=n;i++)
42             ans+=count(i);//第一轮的期望
43         printf("Case %d: %.7lf\n",c++,ans*k);
44     }
45     return 0;
46 }
时间: 2024-10-09 07:52:41

lightOJ 1317 Throwing Balls into the Baskets的相关文章

LightOJ - 1317 Throwing Balls into the Baskets 期望

题目大意:有N个人,M个篮框,K个回合,每个回合每个人可以投一颗球,每个人的命中率都是相同的P,问K回合后,投中的球的期望数是多少 解题思路:因为每个人的投篮都是一个独立的事件,互不影响,所以每回合投中的球的期望数是相同的 只需求得一回合的期望再乘上K就答案了 #include<cstdio> #define maxn 100 double ans, p; int n, m, k; int c[20][20]; void init() { c[1][1] = c[1][0] = 1; for(

Light OJ 1317 Throwing Balls into the Baskets 概率DP

?n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w 当中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 终于答案为w*k #include <cstdio> #include <cstring> using namespace std; double dp[20]; dou

LightOj_1317 Throwing Balls into the Baskets

题目链接 题意: 有N个人, M个篮框, 每个人投进球的概率是P. 问每个人投K次后, 进球数的期望. 思路: 每个人都是相互独立的, 求出一个人进球数的期望即可. 进球数和篮框的选择貌似没有什么关系, 所以给的这个M并没有什么卵用.... 每个人进球数的期望为:E = sigma (i * C(K, i) * p ^ i * (1 - p) ^ (k - i)); 总的进球数期望为:N * E 代码: 1 #include <cmath> 2 #include <cstdio>

LightOJ 1317 第六周比赛A题

A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu 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 dista

LightOJ1317---Throwing Balls into the Baskets 解题心得

原题: 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 diff

LightOJ1317---Throwing Balls into the Baskets (概率dp)

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 m

light oj 1317

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 differen

CodeForces - 316D3 PE Lesson

Discription Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises

Throwing Dice LightOJ - 1064

n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x? Input Input starts with an integer T (≤ 200), denoting the number of test cases. Each test case contains two integers n (1 ≤ n < 25) and x (0 ≤ x <