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*第一轮的期望。

代码:

 #include<cstdio>
#include<iostream>
using namespace std; int t,n,m,k;
double p,ans;
int a[][]; void init()
{
a[][]=;
a[][]=;
for(int i=;i<;i++)
{
a[i][i]=;
a[i][]=;
for(int j=;j<i;j++)
a[i][j]=a[i-][j]+a[i-][j-];
}
} double count(int j)
{
double b=1.0;
for(int i=;i<j;i++)
b=b*p;//投中的期望
for(int i=;i<n-j;i++)
b=b*(1.0-p);//没投中的期望
return b*j*a[n][j];
} int main()
{
int c=;
scanf("%d",&t);
init();
while(t--)
{
scanf("%d%d%d%lf",&n,&m,&k,&p);
ans=0.0;//小数
for(int i=;i<=n;i++)
ans+=count(i);//第一轮的期望
printf("Case %d: %.7lf\n",c++,ans*k);
}
return ;
}

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

  1. LightOJ - 1317 Throwing Balls into the Baskets 期望

    题目大意:有N个人,M个篮框.K个回合,每一个回合每一个人能够投一颗球,每一个人的命中率都是同样的P.问K回合后,投中的球的期望数是多少 解题思路:由于每一个人的投篮都是一个独立的事件.互不影响.所以 ...

  2. Light OJ 1317 Throwing Balls into the Baskets 概率DP

    n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...

  3. LightOj_1317 Throwing Balls into the Baskets

    题目链接 题意: 有N个人, M个篮框, 每个人投进球的概率是P. 问每个人投K次后, 进球数的期望. 思路: 每个人都是相互独立的, 求出一个人进球数的期望即可. 进球数和篮框的选择貌似没有什么关系 ...

  4. ACM第六周竞赛题目——A LightOJ 1317

    A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  5. LightOJ 1317 第八次比赛 A 题

    Description You probably have played the game "Throwing Balls into the Basket". It is a si ...

  6. LightOJ 1317 第六周比赛A题

    A - A Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu   Description Y ...

  7. LightOJ 1317

    Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %lluDescription You probab ...

  8. LightOJ - 1323 - Billiard Balls(模拟)

    链接: https://vjudge.net/problem/LightOJ-1323 题意: You are given a rectangular billiard board, L and W ...

  9. lightoj 1064 Throwing Dice

    题意:给你n个骰子,求n个骰子的和不小于x的概率. 刚开始想每给一组数就计算一次~~太笨了- -,看了别人的代码,用dp,而且是一次就初始化完成,每次取对应的数据就行了.WA了好多次啊,首先不明白的就 ...

随机推荐

  1. python进阶1--数据库支持

    数据库支持 1.连接和游标 1)connect函数,该函数有多个参数,而具体使用那个参数取决于数据库.--连接数据库 常用参数: dsn:数据源名称 user:用户名 password:用户密码 ho ...

  2. 设置cmd的codepage的方法

    设置cmd的codepage的方法 有时候,我们的cmd.exe的codepage和字体等会变化,比如突然由中文变成英文的codepage(因为一些sh程序的干扰). 下面是修正方法: [HKEY_C ...

  3. was配置oracle RAC集群的数据源

    在WebSphere中配置配置Oracle RAC集群的数据源,假设Oracle RAC双击分别为 HOST1 与 HOST2 , 端口为1521 ,服务名为 orcldbservice,则配置的UR ...

  4. Android实现获取应用程序相关信息列表的方法

    本文所述为Androdi获取手机应用列表的方法,比如获取到Android应用的软件属性.大小和应用程序路径.应用名称等,获取所有已安装的Android应用列表,包括那些卸载了的,但没有清除数据的应用程 ...

  5. Hibernate 配置详解(12) 其实我也不想用这么土的名字

    hibernate.hbm2ddl.import_files 这个配置用于在hibernate根据映射文件执行DDL之前,如果我们自己设置了要事先运行的SQL文件,hibernate就会先执行这些SQ ...

  6. swig模板 html代码自然状态下输出是转义的,必须加一个函数来转换为html代码;

    <div>{{o.content|raw}}</div> |raw 相当于一个函数,转义函数,最终输出结果为html代码:

  7. cocos android分析

    来自:http://xiebaochun.github.io/ cocos2d-x Android环境搭建 cocos2d-x环境搭建比較简单,可是小问题还是不少,我尽量都涵盖的全面一些. 下载软件  ...

  8. Mybatis上路_06-使用Java自动生成[转]

    Mybatis上路_06-使用Java自动生成 11人收藏此文章, 我要收藏发表于1个月前(2013-04-24 23:05) , 已有151次阅读 ,共0个评论 目录:[ - ] 1.编写Gener ...

  9. linux 知识整理1linux 常见的目录

    linux 系统现在也是搭配啦图形操作界面. 本人初次学习linux,不是为工作,我的工作是玩Asp.net 的.学习linux 也算是知识的储备吧. 学习linux必须知道一些基本的知识. 目录 用 ...

  10. Javascript对象的声明

    JavaScript 对象 对象由花括号分隔.在括号内部,对象的属性以名称和值对的形式 (name : value) 来定义.属性由逗号分隔: var person={firstname:" ...