我正在尝试确定A队赢得壁球比赛的可能性。两个团队都有3名成员:

团队A:具有40、50和70的能力-团队B具有75、25和30的能力。

赢得至少两场比赛的球队将赢得比赛。如果A组按照上述顺序进行比赛,而B组则随机选择:

(a)估算TeamA获胜的可能性

(b)如果一队赢得两场比赛后比赛结束,那么预期的比赛次数是多少。

我使用方程式计算出A队赢得一轮的概率:(A队获胜的概率)= rA /(rA + rB)

到目前为止,我只是试图计算出A队获胜的机会。

import random

def game(a,b,c,d,e,f):

    overallprob = 0

    for item in [a, b, c]:
        probA = item / (item + d)
        overallprob = overallprob + probA

    for item in [a, b, c]:
        probA = item / (item + e)
        overallprob = overallprob + probA

    for item in [a, b, c]:
        probA = item / (item + f)
        overallprob = overallprob + probA

    print "Chances of team A winning =",round((overallprob / 9*100),2),"%"

game(40.0,50.0,60.0,75.0,25.0,30.0)


哪些打印:

Chances of team A winning = 56.04 %


我不确定这是否正确,我想知道在(b)部分是否可以获得任何帮助,因为我不确定从哪里开始

最佳答案

from itertools import permutations, product

def main():
    teamA = [40, 50, 70]
    teamB = [75, 25, 30]

    # Compute two averages by processing every possible match:
    #   pa   Probability that Team A wins a match.
    #   ng   Expected N of games in a match.
    tot_pa, tot_ng, n = (0, 0, 0)
    for As, Bs in product(permutations(teamA), permutations(teamB)):
        pa, ng = prob_a_wins(As, Bs)
        tot_pa += pa
        tot_ng += ng
        n      += 1

    print tot_pa / n  # 0.61233
    print tot_ng / n  # 2.50580

def prob_a_wins(As, Bs):
    # Probabilities that Team A wins game 1, 2, 3, and the match.
    g1, g2, g3 = [ a / float(a + b) for a, b in zip(As, Bs) ]
    pa = (
        g1       * g2            +  # win g1 and g2
        g1       * (1 - g2) * g3 +  # win g1 and g3
        (1 - g1) * g2       * g3    # win g2 and g3
    )

    # Probabability of a two-game match, and expected N of games.
    two = (
        g1       * g2 +        # win  g1 and g2
        (1 - g1) * (1 - g2)    # lose g1 and g2
    )
    ng  = two * 2  +  (1 - two) * 3

    return (pa, ng)

main()

07-25 21:15