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


    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 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 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 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 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个篮框,每个人投进球的概率是P。
    •问每个人投K次, 总进球数的期望。
    即 1 * C(1, 1) * 0.5^1 * 0.5 ^ 0
    •每个人投球是相互独立的, 互不影响。求出一个人投K次的期望再乘以N即可。
    •进球概率是P, 没有指定进哪一个篮框, 所以总的进球概率还是P(M* 1/M *P)
    •每个人的进球数期望是:
    •E = ∑(i * C(K, i) * P^i*(1 - P)^(K - i))
    •最终答案 = E * N.
    程序代码:
    #include<cstdio>
    using namespace std;
    int main()
    {
        int t,Case=0;
        scanf("%d",&t);
        while(t--)
        {
         double p,ans;
         int m,n,k;
         scanf("%d%d%d%lf",&n,&m,&k,&p);
         ans=n*k*p;
        printf("Case %d: %.6lf
    ",++Case,ans);
        }
    return 0;
    }
    版权声明:此代码归属博主, 请务侵权!
  • 相关阅读:
    vue.js初识(一)
    node.js安装
    array_unshift
    查看php 某个服务的进程数
    获取src 内容
    微信支付 composer 方法 --- 实测有效
    tp5.1 model 方法下的like语句查询
    tp5.1 where 时间查询
    nginx conf 文件
    怎么用Ubuntu系统制作Ubuntu系统盘
  • 原文地址:https://www.cnblogs.com/www-cnxcy-com/p/4750495.html
Copyright © 2020-2023  润新知