zoukankan      html  css  js  c++  java
  • 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;
    }
    版权声明:此代码归属博主, 请务侵权!
  • 相关阅读:
    计算与软件工程 作业一
    C语言程序设计数组实验实验报告
    C语言程序设计第五次实验报告
    C语言程序设计第四次实验报告
    C语言程序设计第三次实验报告
    C程序设计实验报告第二次实验
    关于证书如何完成身份验证(SSL证书)
    openflow流表项中有关ip掩码的匹配的问题(控制器为ryu)
    解决sublime安装插件被墙失败的方法
    区块链技术与应用(二)之比特币中的数据结构
  • 原文地址:https://www.cnblogs.com/www-cnxcy-com/p/4750495.html
Copyright © 2011-2022 走看看